Java VM & .NET Performance Comparisons 104
johnhennessy writes "Just came across some good virtual machine performance benchmarks (on Mono's mailing list). It covers executing java bytecode via a host of different Java runtimes and also the mono runtime. Not only does it give numbers for IBM's runtime (1.4.2 and 1.3.1), Sun's runtime (1.5.0 and 1.4.2), GCJ, Mono, Jikes and much more! These numbers are also given for both Intel and Opteron (where relevant). Before the flames begin, don't forget to read the authors description of how the benchmark was carried out. Hopefuly this should inspire educated discussion on ones favourite JVM/CLR."
No jRocket (Score:2, Insightful)
But I don't see commerical and highly optimized products like JRocket on there (BTW, I think the JRocket JVM is free, support costs).
Sun's JDK most powerful, no surprise. (Score:1, Flamebait)
Re:Sun's JDK most powerful, no surprise. (Score:4, Insightful)
Sun has a better JVM not because they have some mystical insight because they invented it, but because they made it a huge part of their company survival strategy. Improving the JVM gets a very high priority in the company. IBM on the other hand might not care if they are second, as long as their performance is competitive.
Re:Sun's JDK most powerful, no surprise. (Score:5, Informative)
Re:Sun's JDK most powerful, no surprise. (Score:4, Insightful)
The techniques necessary for compiling Java well have largely been around since long before Sun even released Java. Sun has no special, secret knowledge there, they have just been hacking on their implementation longer than anybody else. If anything, Sun's progress on Java has been pokey.
Sun Java is probably pretty close to what is theoretically possible, so they will largely be standing still, while other implementations will keep improving until they also hit the limit. In a couple of years, you can expect that all actively developed JVM and CLR implementations will have roughly the same performance on comparable code.
Re:Sun's JDK most powerful, no surprise. (Score:1)
Flamebait this guy.
I mean... Obviously he didn't read the charts, and, i mean jesus christ read what he wrote which parses too
but no explination as too... uhm... why?
*boggle*
Lots of pretty numbers (Score:1)
But, what are those numbers?
I'd presume they are meant to be seconds, but the difference is so vast it can't be. Can it?
Re:Lots of pretty numbers (Score:3, Informative)
GCJ slower than a native JVM? (Score:3, Insightful)
What surprises me is that GCJ is never faster than a 'real' JVM. You'd think that natively compiled and optimized code would be faster than an interpreter. I guess there's optimization work to be done in gcjlib.
Re:GCJ slower than a native JVM? (Score:2)
Re:GCJ slower than a native JVM? (Score:2)
Isn't it the GIJ interpreter against the others?
My guess would be no, because they specify -O0 and -O2 for the gcj runs. They wouldn't make sense for the gij interpreter.
Re:GCJ slower than a native JVM? (Score:2, Troll)
I already know what I want. I want to open a file and read it. I don't want to have to worry about if the file is buffered or not, or if it has a method to read a line at a time. Just gimme an old-fashioned fopen () function.
So, am I crazy, or has anyone else thought this to
Re:GCJ slower than a native JVM? (Score:4, Insightful)
Re:GCJ slower than a native JVM? (Score:2)
Thanks for reaffirming that. I thought I was going crazy. er, something like that.
I was only half serious about it anyway. I really don't touch Java that often and I work with C++ and Python every day, which explains why I have to look things up all the time.
But I have a comment/question. The example you gave about the layered API adapting to a NetworkStream easily strikes me as something that should really be in the OS, or maybe a JVM thing. Instead of putting it all the way up into
Re:GCJ slower than a native JVM? (Score:5, Interesting)
Furthermore, I don't think it is necessarily true that everything-is-a-file is the best abstraction for all IO forever and ever. If you want such an abstraction simply use java.net.URL and write protocol handlers for any protocols not provided. So far, http[s]:// and file:// (and probably some others) work out of the box. Add your own.
Re:GCJ slower than a native JVM? (Score:3, Interesting)
Re:GCJ slower than a native JVM? (Score:2)
Re:GCJ slower than a native JVM? (Score:3, Insightful)
Re:GCJ slower than a native JVM? (Score:1)
*ahem*
(BufferedReader, for most things, is faster than a plain Reader, and in addition has the handy readLine() interface)
Sometimes you just have to learn the libraries for your language. The Reader system, BTW, is nifty in that
Bug (was Re:GCJ slower than a native JVM?) (Score:4, Informative)
If you want to read characters from a file (or socket) you need to come up with some way to agree on the character encoding and specify it precisely. Not even HTTP does a good job of this--you don't know the character encoding of a request or response until the Content-Type header has been transferred, and often not even then.
What's the character encoding for URLs and domain names [cr.yp.to]? Convention seems to be settling on UTF-8 but AFAIK it's just that.
The equivalent technique that's less risky (but of course much more verbose) is:
Where "UTF-8" is a sane default non-lossy character encoding. If you don't know the encoding that was used to write the file you're about to read, you're sort of screwed. You can try some heuristics to try to detect its encoding, or if you're "lucky" you might find a Unicode Byte Order Mark [unicode.org].
Note that none of this headache is particular to Java, it's just that the designers of Java knew early on that a character is not a byte and formalized that distinction (poorly at first) in the language and libraries.
Re: Bug (was Re:GCJ slower than a native JVM?) (Score:2)
Sometimes you do want to use the platform's default encoding. In fact, I'd suggest, most of the time. In particular, it's the right default setting; if your program knows what encoding it wants to use, then it can go right ahead and use it -- but a lot of the time, it won't know, and the platform default is the Right T
Bad idea. (Score:2)
If you want Java, then use Java.
One of Java's most significant advantages is that it doesn't expose pointers or dynamic memory allocation to the programmer. This is a Very Big Deal, because there are only two kinds of programmers out there: the sort who know they can't be trusted to never leave a dangling pointer or a memory leak, and the sort who are living in denial.
Why in the world would you want to throw away one of Java's major
Re:Bad idea. (Score:2)
The guy was complaining about Java's not-so-great I/O API. That doesn't mean he doesn't like automatic memory management. Java's particular I/O API is not a prerequisite for automatic memory management.
I also don't think he's complaining about "the inconvenience of learning something new." A well-designed API doesn't require much storage sp
API Docs (Score:3, Interesting)
I must say that is mitigated by the fact the Java has hands down the best API documentation for any platform. Really what more could you ask for. Combined with the Swingset and there SWING component guide [sun.com], who could ask for anything more in terms of documentation? Mind you I'll agree that getting used to all the layers can be a burden when first learning but it becomes elegant once you see the big picture.
Re:API Docs (Score:2)
I agree that good documentation helps and that Java libraries are well-documented. However, that's still not a reason to downplay complaints against bad APIs.
You also shouldn't assume that people who don't like some Java API's are just OO-deficient C people who don't see the "elegance" of layering. You have to layer in the right places.
Re:API Docs (Score:2)
Re:API Docs (Score:2)
Re:API Docs (Score:2)
I don't think "because everything else is done that way" is a good enough reason. If you had an ObjectOutputStream, there's no reason to expose the raw write() methods. If you want t
Re:API Docs (Score:2)
Re:API Docs (Score:2)
If the philosophy caused the crappy class, then, by definition, there is something wrong with the philosophy. If the philosophy didn't cause the crappy class, then the API is inconsistent. In Java, it's a little of both.
The original Java API philosophy was "let's make everything a subclass." An example of this would be deriving from java.lang.Th
Re:API Docs (Score:2)
Re:API Docs (Score:2)
I was using it as an example of where it is possible to use inheritance (and people do) but it is a bad idea. I used that example because you said you weren't familiar with ObjectOutputStream. But thanks for another installment of "Intro to OO for Literature Majors". Again, your examples are at such a high level that they won't help anyone but absolute beginners. You have to look at complex real-world API requirements if y
Re:API Docs (Score:1)
oh i'd agree with that but not in away which you could develop from those two examples. hell i have a problem with people claiming the existence of good and evil...
Re:Bad idea. (Score:2)
Re:GCJ slower than a native JVM? (Score:2)
Else
Re:GCJ slower than a native JVM? (Score:4, Informative)
Besides, there isn't much reason why a JIT should be slower than a natively compiled binary, besides startup time. The code still gets compiled, just at runtime. In fact, since profiling feedback is close at hand, it has an advantage (though newer versions of gcc/gcj can use profiling data to optimize as well).
Re:GCJ slower than a native JVM? (Score:2)
Re:GCJ slower than a native JVM? (Score:2)
Which is exactly my point: GCJ CAN afford those more expensive static optimisation techniques, like full stack caching. This should help a lot, even though it doesn't have access to runtime data.
Re:GCJ slower than a native JVM? (Score:2)
Yes, but on the other hand, the time used to instrument the currently running executable and optimising it is slowing down the execution.
Whereas on a profiling computer, the profiling run is used to accelerate the executions which occurs *after* this one..
Re:GCJ slower than a native JVM? (Score:1)
Both approaches have advantages and drawbacks.
Java is not interpreted. (Score:5, Informative)
Code run in modern Java VM's is not interpreted...it's compiled on the fly with whatever performance optimizations are appropriate for the particular machine at that particular point in the execution path.
Re:GCJ slower than a native JVM? (Score:5, Informative)
Re:GCJ slower than a native JVM? (Score:2)
Java code executed with Sun or IBM JVMs is not interpreted, but compiled to native and heavily optimized code.
No argument there, but wouldn't you think that compiling and optimizing the code every time you run a Java program would make it slower than compiling and optimizing it once ahead of time? All of that compiling and optimizing is included in the performance specs for the JVM's, but they almost uniformly trounce GCJ.
Re:GCJ slower than a native JVM? (Score:5, Informative)
This doesn't matter for a compiler working at runtime, as it knows about the capabilities of the CPU and just uses them if possible (I know that the JVM uses SSE when available, though I haven't found out what exactly it is used for).
A JIT/DynamicCompiler also knows everything about your CPU, for instance Cache sizes,... and can exploit that knowledge to further optimize the code or data layout.
Also: you have to keep in mind, that Java (like
Now: these optimizations have one problem: they may be accurate when the code is generated... but what happens when a new class is loaded? For instance, the compiler devirtualizes a method in class A, because Class Hierarchy Analysis tells him, that this method is never overridden. So... 10 minutes later, a class is loaded, that is derived from class A, and overrides the aforementioned method... so... the code is suddenly incorrect. In this case, the dynamic compiler, takes back the old optimization, and everything is OK again.
This kind of scenario makes it necessary for many optimizations to have a system (compiler) working at runtime.
Mind you: Runtime code loading or generation is a point where gcj gets really slow, because then it has to run that code with gij (the interpreter). There are people that got Eclipse compiled with gcj, but they ran into that problem too (the Plugins in Eclipse are loaded at runtime; they worked around that by compiling the plugins as shared libraries).
Re:GCJ slower than a native JVM? (Score:2)
Thanks for the informative and thoughtful reply. In my particular case, I'm evaluating running eCos+GCJ vs Wonka or Kaffe on an embedded processor. I had assumed that the GCJ-compiled code would be faster, but now I'm not so sure. I doubt Kaffe or Wonka do extreme optimization, but it sure got my attention when GCJ didn't compete favorably with 'real' JVMs. The main snag with GCJ is static compilation - eCos does not have any dynamic loading available, so things like System.loadLibrary() cause real problems
Re:GCJ slower than a native JVM? (Score:1)
Here's the link to the LinuxJournal text talking about getting gcj to compile Eclipse: http://www.linuxjournal.com/article.php?sid=7413.
Re:GCJ slower than a native JVM? (Score:1)
System.loadLibrary() is used for loading native code. If you wish to load a class file at runtime, you may have to implement your own ClassLoader.
Re:GCJ slower than a native JVM? (Score:2)
Thanks for the info. I'm trying to jam a statically-linked gcj executable into an embedded device. When trying to compile a JNI-based open source jar into an object file, it's not always possible (license-wise) to go in and hack the code to suit my needs. Most JNI implementations call System.loadLibrary() to load the native half of their code, making it unusable in a statically-compiled executable. Someone suggested that GCJ support an option to specify what libraries are statically linked - this would help
Re:GCJ slower than a native JVM? (Score:5, Informative)
On SUN, -server means that a full JIT is applied to all code before it is run (though some enhancements might not be possible until a few runs are performed; run-time profiling / enhancements). -client means that code is only JIT'd if it's run more than a few times (meaning it's a hot-spot which is worth trading off compile-time for run-time). While -client does a good amount of inital JITing, you can see that there's not a terrible amount of performance difference between -client and -server. At least not compared to gcj.
This should convince you that the overhead of compiling is nothing compared to the amount of work being executed. In my experience, runing tomcat with -server v.s. -client is night-and-day as far as load-time is concerned (2 to 3 times slower to get into a state ready to accept web-requests), but I don't notice tremendous differences in runtime performance (compilation is hidden in between web requests). What does this say about the differences between tomcat and the benchmark? Again that there must be several orders of magnitude more time spent executing than loading.
If you wanted to write "ls" in java, then yes, you'd prefer something LIKE gcj (don't know what their load time is so I can't say with certainty). Something that does very little, and thus wants a minimalist foot-print is not going to like java. Even perl was too much over-head a few years ago for most small tasks, which is why awk, sed are still in use today, even though perl totally blows them out of the water for even the most trivial tasks. Today machines are fast enough that the human-perceivable difference in latency goes away. Perhaps when we reach 10GHZ VLIW 1024reg CPUs and have 1TB of RAM, the latency of "java -server" will go away too. Note multi-CPU / hyper-threading isn't going to help single-application load-time.
SUN JVM 1.5 has already started to do what you're essentially asking though; they've pre JIT'd most of the rt.jar file. Much of this file is used for even the most trivial possible hello-world application, so it made sense to pre-store that material. I suspect in future versions, we'll see dynamicly cached JIT code, which would tremendously improve start-up time. Of course, with major java applications (web servers, database wrappers) the only time you tend to restart java is when you're upgrading the jar files, so who knows if anyone really cares.
Re:GCJ slower than a native JVM? (Score:1)
That said, as the environment in which the program is running changes (such as the supply of available memory decreases), the CLR may decide its worth a recompile to optimize to changed conditions.
Re:GCJ slower than a native JVM? (Score:4, Informative)
With GCJ-built code, you can put everything needed on a single installation medium.
Re:GCJ slower than a native JVM? (Score:2)
Thanks for the reply. Please see this comment [slashdot.org] describing my situation and exactly what you've mentioned.
Re:GCJ slower than a native JVM? (Score:3, Informative)
I believe you are incorrect. You can redistribute the JRE, you may not redistribute the SDK. Most people only need the JRE. So it's unlikely to be much of a problem.
Re:GCJ slower than a native JVM? (Score:1, Informative)
Not really.. only on very strict conditions.
Re:GCJ slower than a native JVM? (Score:2)
In principle, you can redistribute the JRE, but you probably don't want to: it's big, it's an intrusive install for the user, and it may not be compatible with the target system.
Re:GCJ slower than a native JVM? (Score:2)
The JIT inside a Java or CLR (C#) runtime has more information available to it for optimization. That means that, ultimately, it should be able to do better than gcj on long-running, compute-intensive jobs.
Re:GCJ slower than a native JVM? (Score:4, Interesting)
The use of the word interpreter is really suggestive. A compiler is nothing more than a static interpreter. The only two differences with a JIT compiler is that it permanently stores the results of the interpretation and that it has much less information to predict the performance of the code it is generating. A static compiler will do well on simplistic programs whereas a run-time optimizing jit compiler will be able to always match the performance of a static compiler (simply by running the same optimizations) or beat it (by applying optimizations to address observed performance bottlenecks in the running program). Of course this costs some computation time but you can take that into account as well when deciding to optimize or not.
In simplistic scenarios such as simple benchmarks, there won't be much to gain from run-time optimization. So performance is about equal with a slight advantage for the static compiler because it is not wasting resources on figuring out how to optimize the program. Despite this GCJ's performance is disappointing even on these kinds of benchmarks.
To put it simpler (Score:2)
Also gcj-compiled programs may have worse garbage collection. AFAIK a simple conservative GC is used.
I don't think commonly-used Java JIT compilers do much more than this.
JRocket? (Score:3, Interesting)
I'd also be very curious to see an independent mark of BEA [bea.com]'s JRocket JVM [bea.com], which is supposed to blow Sun and IBM away on X86.
Re:JRocket? (Score:1)
what test was used for JESS? (Score:2, Interesting)
excellent for C# (Score:5, Interesting)
The level of performance of Mono is even more impressive given how young the project is; at the same point in time in its evolution, Sun had barely managed to produce a JIT compiler.
Re:excellent for C# (Score:2)
I haven't seen any decisive language feature that gives C# any edge over Java. Most of it is syntactic sugar which is nice to have but not really that important if you have code compl
Re:excellent for C# (Score:2)
When Java came out, garbage collection already was a mature field (Java's GC is still not state-of-the-art). Dynamic compilation and dynamic optimization had also been around for quite a number of years. So, both the Java and Mono implementors had the benefit of hindsight. In fact, Sun had many of the world experts on th
Also... (Score:2)
Also, the lack of unsigned types in Java can sometimes be painful.
Re:Also... (Score:2)
That, in particular, Sun has a good excuse for. A good JIT should be able to make up for that. Also, declaring a class or method "final" can make the JIT's job simpler.
But there are several other areas where the JIT can't compensate for language differences. For example, template classes used with primitive argument types are much more efficient in C#.
Also, the lack of unsigned types in Java c
Re:Also... (Score:1, Interesting)
If you want to use a macro preprocessor with Java, there is nothing stopping you from doing so. The fact that the base language doesn't include a macro system is immaterial, as there are many external alternatives.
Re:Also... (Score:1)
Re:excellent for C# (Score:1)
>a mature field (Java's GC is still not
>state-of-the-art).
WTF? Sun JVMs have had state of the art GCs for years. Actually, there's not just one GC, but a lot of them in the JVM. The default version is a Generational GC. You can choose options like incrementality (to avoid GC pauses, or at least to minimize them). You can choose a Parallel GC (which exploits several CPUs for marking and collections).
There is a GC option for large heaps (Scavenger a
Re:excellent for C# (Score:2)
There is Sun's feature list, and then there is actual implementation and performance, and that hasn't been all that impressive. Until fairly recently, Sun Java still had 12 byte object headers (I think they are still 8 bytes now, but I frankly just don't care anymore).
The only thing that remains is stuff like Escape Analysis
Yes, important stuff like that, stuff that other systems have had for many years. And other systems also have planned ahead in th
Re:excellent for C# (Score:1)
Great statement... so, what actually hasn't been impressive?
Re:excellent for C# (Score:2, Flamebait)
So it still has 8 byte object headers, after all these years, instead of 4 bytes or less. (I qualified my statement only because I thought Sun might have fixed this in 1.5, but apparently not.)
NET still only [...] Mono actually uses the Boehm GC,
Yes, the Sun Java implementation is more mature than
Sun has made the right decision to keep the reference-type-only s
Re:excellent for C# (Score:1)
>than
> point?
My point? You complained about Sun (claiming that Sun claims to have GC options, but that they have implementation problems).
>The semantics of value classes are supposed to be
>different. Giving everything reference semantics
>would be the wrong thing to do even if the
>compiler managed to perform every possible
>optimization.
And what would the advantage of that be? Having only one w
Re:excellent for C# (Score:3, Interesting)
I didn't "complain" about Sun. I simply pointed out that they started out with a pretty poor implementation and that it has taken them a long time to bring it to maturity. I also pointed out that C# is competitive with Sun's much older Java implementations now in terms of performance.
And what would the advantage of that be? Having only one way of accessing data is simpler. Havin
Re:excellent for C# (Score:1)
You're wrong about Javas openness. The JVM spec is open:
http://java.sun.com/docs/books/vmspec/2nd- e dition/ html/VMSpecTOC.doc.html
The Java language spec is open as well:
http://java.sun.com/docs/books/jls/second_e dition/ html/jTOC.doc.html
Yes, I agree, they don't have a big "ECMA" or "ISO" badge, but well... since when were those worth a penny. C++ has been ISO certified for years or decades, but
Re:excellent for C# (Score:2)
"Open" means that you can implement the spec as you like, and the JVM spec is not open (and neither are the language or the libraries): read the license [sun.com] linked to at the bottom of the spec that you yourself point to. Also read Stallman's take on this [newsforge.com] if you don't believe me.
Yes, I agree, they don't have a big "ECMA" or "ISO" badge, but well... since when were those worth a penny.
They guarantee that Microsoft can't play the kinds of legal games that Sun has been playing with the Ja
Re:excellent for C# (Score:1)
That should be rephrased as "I, jeif1k, think, that 'open' means...". The term "open" means something else to everyone, there's no specific definition. The JVM and Java lang spec are open for people to read, and to implement. People have done so for years (I mentioned the JVMs, and there are countless extensions of the Java language, like AspectJ, GJ,
>They guar
Re:excellent for C# (Score:1)
You missed the explanation note here. I'll add it for you:
**) I'm an Anonymous Coward who can't read a manpage to check the option to use to enable full optimizations.
BTW: it's -O=all.
Any reference numbers for C/C++? (Score:2)
Obviously some of the benchmarks would be apples-and-oranges, but there should be a few of them that would allow a direct comparison...
Java GUI performance (Score:4, Interesting)
At home, I run Linux on a P4-2.6G w/ HT. Frankly, Eclipse runs like ass on Linux. I've tested it with pretty much every available JRE/J2SDK for Linux, and it sucks with all of them.
This is using Eclipse with SWT compiled for GTK+. I have used WebSphere with the Motif libraries, and it was quite fast, but Motif is just horrid to use next to GTK+. But, SWT with GTK+ is just so damned slow. I've run Eclipse on my PowerBook G4, and it sucks even more on Mac OS.
I find this funny that Windows is the best supported platform for Java GUI programs, considering that MS hates Java. So, is GUI performance with Java apps ever going to be acceptable on Linux? It's really pathetic at this point.
I know Sun added OpenGL 2D acceleration to their 1.5.0 JRE, but that gives me lots of artifacts with the included demo programs, and SWT doesn't use the acceleration at all.
Re:Java GUI performance (Score:1)
I've found that having the proper video drivers under linux makes a huge difference in X performance. Under Windows, you're probably using graphics drivers with DirectX support. You should be using drivers under linux that support DRI.
Re:Java GUI performance (Score:1)
Re:Java GUI performance (Score:2)
Re:Java GUI performance (Score:1)
Springs Eternal (Score:2)
Itanium java performance? (Score:2)
On a serious side, I'm curious about java benchmarks on Itanium. I've seen a tender where the specs were java on Itanium for production and java on x86 for development (d'oh).
Anyone have benchmarks comparing Java performance on Itanium vs x86? I've seen some on the SPEC website, any others?
'In good time' compilation with Mono... (Score:1)
The docs say that it (can't remember the correct name
Quite a good idea, actually, most of the time you do have the source avaible, and you can probably run it off MSIL bytecode too.