Re:In what cases is Java faster than C++?
by froydnj on Wednesday February 16, 2011 @01:40PM
(#2227639)
It's worth noting that proposals, like JSR 83 (http://jcp.org/en/jsr/detail?id=83), to address Java's multi-dimensional array shortcomings have been around for quite some time. Of course, JSR 83 just sat around for five years before being abandoned; maybe Java folks don't think efficient multi-dimensional arrays are useful and/or common.
Re:In what cases is Java faster than C++?
by kirktrue on Wednesday February 16, 2011 @01:33PM
(#2227602)
Yes, the array bounds checks are inefficient, but IIRC, they're there to prevent buffer overflows that are/were prevalent in C applications.
Re:In what cases is Java faster than C++?
by getsat on Wednesday February 16, 2011 @04:08PM
(#2228303)
We're definitely still on the "are" side of that one, unfortunately.
If you eschew all this and write strongly optimized code, I think the single biggest spot where Java is unquestionably slower than C/C++ is in array accesses. In Java, to set a slot in a two-dimensional array Java must first test to see if the array is non-null, then test that the X bounds are correct, then test to see if the appropriate Y subarray is non-null, then test to see if the Y bounds are correct, then finally set the value.
In C the compiler does a multiply and an add and sets the slot.