Java was initially slow before the JIT but today performance is pretty close to C++. I want to know if someone has done measurable performance comparisons between the two langu
In many ways this is like comparing apples to oranges.
C++ is built on the notion that you don't pay a cost for anything you don't use. If you manage memory yourself, if you don't use virtual functions, etc.
Java doesn't give you that freedom. It gives you features that you may not even want. For all you may want to allocate memory yourself, you will have to use heap objects for everything, so you will take a garbage collection impact.
Once you start talking about GUIs, it's an even more difficult comparison since different UI frameworks and toolkits have different performance issues. For example, Swing/AWT will typically be slower than something written directly for the native OS. In C++, you will rarely find a truly portable toolkit, etc.
I think that when developers started openoffice, Java was much slower and the UI toolkits were slow and ugly. Tools like Eclipse prove that you can build relatively nice UIs even in Java, though admittedly, SWT is a toolkit that does a lot of things at the native level.
To me, this question is a bit of a red herring (perhaps not intentional). Its really the wrong question to ask.
The first questions to ask are these
Here are some good 'why' questions
I suspect that you really need to focus on the Performance aspects of your program (with a capital 'P') instea od the performance (little 'p') aspects first. If you can get to the point where the language is in the way, then you have done a really good job to that point with respect to performance.
For new code - its important to plan for performance and efficiency up front. I always recomend that performance and efficiency treated just like any other feature (they are features): just like UI bling, or reliability. Of course this will depend on many things - but when its important you need to plan for it up front:
The reason I think this is a red herring is that rarely does one just get to choose between C++ and Java - they are very, very diffrent languages with very different run times. I suspect is is more usual that you have other constraints pushing you one way or other - these will be higher order factors than language performance. Computability with existing code, skills and experience of the exiting staff, etc. etc.
The environment makes a difference too. For example, Java would almost never be the right choice for a widows client (vs. a web) application. Conversely, native C++ would almost never be the choice for a web based app. (note, I am a windows guy - the situation may be very diffretnt in *nix).
Some points to take into account:
If you get a better C++ compiler, your code doesn't become faster. You need to recompile it first. If you get a better JVM, all your Java code will run faster
If you get a better C++ compiler/JVM, you will see 10-20% faster execution, usually in corner cases. If you find a better algorithm to achieve what you need, you can easily get 1,000%-10,000% more performance, sometimes even more.
So today, if performance is an issue, you should look at these two facts:
Anything else is just FUD.
Languages don't have a speed. Neither the Java or C++ language specs specify "and programs must be compiled to be this efficient".
Each language specifies a list of things the program must do, or at least, appear to do, which in some cases put an upper bound on how efficient a program can be, but often, a clever compiler can ignore these rules in individual programs, because all that matters is that the program behaves as if the spec had been followed. Functions can be inlined, heap data can be moved to the stack and so on.
The performance of a program depends on three things: The compiler, the underlying platform/hardware and the program code itself.
Not "the language". The closest you're getting is the compiler.
There are good reasons why either language could be faster than the other. C++ makes fewer promises that could potentially slow down program execution, but Java is JIT'ed, which means it could potentially take advantage of runtime information to optimize the code, which C++ can't easily do... And then again, nowhere in the spec does it say that C++ must not be jit'ed. Just like I believe there are also Java compilers that generate native code instead of JVM bytecode.
Your question only makes sense if you have a specific computer you're running on, a specific compiler for each language, and a specific implementation of your program in each language, in which case you could just run both to see which was fastest.
Garbage collection is another wonderful example. Of course garbage collection implies some overhead, but it also enables some significant shortcuts. Heap allocation is ridiculously cheap in managed languages like Java or .NET, because it is managed and garbage-collected. In C++, it's.... unspecified, of course, but in practice, typically very slow, because the OS has to traverse the heap to find a free block of memory in a more or less fragmented memory space. Which is fastest? Depends on the OS. Depends on the compiler. Depends on the source code.
The source code makes a big difference as well. If you take a Java program and naively port it to C++, it will perform like crap. C++ doesn't deal that well with virtual functions, and usually has superior alternatives available you could use instead. Heap allocation can be very slow in C++, so again, naively reimplementing a Java program would be extremely inefficient. And the same applies when going the opposite way. Many C++ idioms would be needlessly slow if ported directly to Java. So even if you've settled on one platform and one compiler, how do you compare the performance of your program? To even get it to compiler, you have to write two implementations of it, and then it is no longer the same program.
However, I think it's fair to say that on most modern hardware, with a modern Java compiler and a modern C++ compiler, most programs can be implemented to be very efficient, and certainly fast enough. But only if you understand the language you're working with, and play by its rules. If you try to write Java code in C++, then Java will magically turn out to be vastly more efficient, and vice versa.
I guess the most concise answer to your question is "No. No one can quantify performance differences between C++ and Java" ;)
I have implemented performance-sensitive applications (physical simulations, financial models) in both C and Java. The reality is that I've always got much larger gains in performance by changing the algorithms than by tweaking the implementation -- but the implementation also matters. As for now, my opinion is that Java is slower than C (I don't have that much experience with numerics in C++), but a lot can be gained by careful tweaking, and this tweaking is a lot easier in Java, since you don't have to deal with segmentation faults, double frees, etc. C++ occupies the middle ground here, as modern C++ techniques (smart pointers, templates, STL containers) offer both speed and relative safety of use.
I don't believe anyone can prove that C++ will always be meaningfully faster than Java for the simple fact that you can always revert to JNI to get native speed from Java.
See, for example, SWT which are the graphical tools built by IBM (I think) meant to replace Swing and give both native performance and look-and-feel.
I, for one, would prefer the ease of development over speed since I consider minimal development time to be more important than raw application speed, especially when I can still get that speed - I can have both the ease-of-development of Java with speed of compiled languages.