Pents90: Java Port of C++ Algorithm Performs Better with No Optimization:
With no attempts to optimize the Java version, it ran 1.2x faster than the C++ version. After some simple optimization of the inner loop in Java, this increased to 1.5x. The nature of the algorithm was a lot of array accesses and floating point arithmetic. In particular, there is an n-dimensional Euclidean distance calculation that takes up the majority of the running time.
We ran our Sun 1.5 JVM on Windows with the -server flag on. With the -server flag off, Java performed quite poorly: 1.7x slower with no optimizations, 1.1x slower with optimizations of the inner loop. The -server flag, despite its name, is not just for servers. It is a flag that indicates to the VM that it should invest in expensive and complex just-in-time compilations that will pay off in the long run. Typical parameters for our algorithm would result in runtimes from several seconds to a few minutes. So, I recommend that all similarly CPU-intensive software make use of this flag.
The conclusion is that just-in-time compilation really works. We ported an algorithm directly from C++ to Java with no attempts to optimize and experienced a 20% performance improvement.
Why am I just hearing of the -server flag now? Grr!
Matt2000 comments:
What this means is that you shouldn‘t be choosing C++ for performance reasons alone anymore unless you can prove it is a case where something specific about C++ will give it an advantage. More fundamentally, it‘s no longer a valid assumption that statically compiled native code will execute faster than an advanced JIT compiler will run it. In fact it‘s probably a better assumption from now on to assume that the static compiler will underperform the dymanic one.
new⇒I hate ASP.NET
CF, why pick that piece of trash?Cold Confusion. Is it finallyreally a OO...
ColdConfusion: Sep 5, 8:36pm