That's been my experience too, for heavy numeric computation. Hotspot can optimize the hell out of plain Java SE.
Something to keep in mind though: architectural considerations matter a whole lot more than the particular programming language you use to implement them. If you keep your programs simple and use tools like Java NIO when appropriate, you can write really fast code in Java. If you pile on framework after framework, of course it's going to be slow, because it's doing a whole lot more work.
It's very easy to write a screamingly-fast Java backend and then lose all your speed gains by sticking it behind Hibernate, JSF, and a half-dozen JavaScript libraries.
Pick something with weird bit twiddling where C is better. I pick some business computing task involving lots of systems integration or some shit where Java is better. And on and on.
Garbage collection is a megawin and you have to be retarded or working on microdevices with 168 bytes of RAM to use C over Java. And that's really where anything on the JVM wins.
No, C++ is not slower than C. Both C and C++ are effectively macro assembler languages, and if you know what the 'macro' expands to, you can gauge the performance. You could implement everything that's in C++ using just pure C and get the same effect, but I surely do not want to manually lay out my vtables nor do I want to replace my C++ templates with C preprocessor macros. :-)
It should also be no surprise that Java, with its runtime dynamic optimization, is able to more strongly optimize code based on runtime performance characteristics than compile time optimizations performed by traditional C and C++ compilers. This is just a guess, but it's also possible that the Java JIT compiler is able to more aggressively optimize the generated code by having more insight into pointer aliasing, whereas you'd need to do whole program compilation to get the same effect with C++. (Plug: LLVM can do whole program compilation. http://www.llvm.org )
As tx said in a sibling post: Because good (performance-minded) C++ programmer has very good idea what kind of assembly instructions his code will turn to. This is why performance-critical code is still written in C++.
C++ slower than C? Isn't that the same thing? Most of the time when I hear "C++ is slow" it usually means someone ran into slow STL+compiler combination. And according to my knowledge GCC is the worst performing compiler out there when it comes to optimizations. BY FAR. Intel and MSVC++ 7.1 eat it for breakfast, even with microsoft's profile-guided optimization turned off.
And by the way, why is it always Java guys who's playing with these benchmarks? Looks like an "inferiority syndrome" to me, C++ hackers just don't seem to care. Do you know why? Because good (performance-minded) C++ programmer has very good idea what kind of assembly instructions his code will turn to. This is why performance-critical code is still written in C++.
Interesting but Mandelbrot is a specific math process. I'd be more impressed if a large application with network I/O, disk I/O, threading, etc was proven to be faster in Java than in C.
[+] [-] nostrademons|19 years ago|reply
Something to keep in mind though: architectural considerations matter a whole lot more than the particular programming language you use to implement them. If you keep your programs simple and use tools like Java NIO when appropriate, you can write really fast code in Java. If you pile on framework after framework, of course it's going to be slow, because it's doing a whole lot more work.
It's very easy to write a screamingly-fast Java backend and then lose all your speed gains by sticking it behind Hibernate, JSF, and a half-dozen JavaScript libraries.
[+] [-] gibsonf1|19 years ago|reply
http://news.ycombinator.com/comments?id=26136
[+] [-] henning|19 years ago|reply
Pick something with weird bit twiddling where C is better. I pick some business computing task involving lots of systems integration or some shit where Java is better. And on and on.
Garbage collection is a megawin and you have to be retarded or working on microdevices with 168 bytes of RAM to use C over Java. And that's really where anything on the JVM wins.
[+] [-] nickb|19 years ago|reply
Here's an interesting link: http://kano.net/javabench/
"JVM startup time was included in these results. That means even with JVM startup time, Java is still faster than C++ in many of these tests."
[+] [-] jey|19 years ago|reply
It should also be no surprise that Java, with its runtime dynamic optimization, is able to more strongly optimize code based on runtime performance characteristics than compile time optimizations performed by traditional C and C++ compilers. This is just a guess, but it's also possible that the Java JIT compiler is able to more aggressively optimize the generated code by having more insight into pointer aliasing, whereas you'd need to do whole program compilation to get the same effect with C++. (Plug: LLVM can do whole program compilation. http://www.llvm.org )
As tx said in a sibling post: Because good (performance-minded) C++ programmer has very good idea what kind of assembly instructions his code will turn to. This is why performance-critical code is still written in C++.
[+] [-] tx|19 years ago|reply
And by the way, why is it always Java guys who's playing with these benchmarks? Looks like an "inferiority syndrome" to me, C++ hackers just don't seem to care. Do you know why? Because good (performance-minded) C++ programmer has very good idea what kind of assembly instructions his code will turn to. This is why performance-critical code is still written in C++.
[+] [-] snorkel|19 years ago|reply