For this kind of algorithm, basically working with arrays of doubles, java should be within 20% of c++ and normally it is just as fast.
For this kind of algorithm, basically working with arrays of doubles, java should be within 20% of c++ and normally it is just as fast.
Please show that it takes 1 whole second (measured after the Java program starts and before it terminates) for the JVM to profile and compile the 100 lines of code.
That would suggest the JVM was pure junk.
Here are 10 cold-run times reported by their program:
Elapsed time is 3.122233018 seconds.
Elapsed time is 2.970587912 seconds.
Elapsed time is 3.110304658 seconds.
Elapsed time is 2.886701204 seconds.
Elapsed time is 2.966404493 seconds.
Elapsed time is 2.905329605 seconds.
Elapsed time is 2.968715703 seconds.
Elapsed time is 2.922929706 seconds.
Elapsed time is 2.906730019 seconds.
Elapsed time is 2.919119506 seconds.
Here are the stats reported by JMH after 200 samples: Result : 2.950 ±(99.9%) 0.015 s/op
Statistics: (min, avg, max) = (2.932, 2.950, 2.984), stdev = 0.017
Confidence interval (99.9%): [2.935, 2.965]Java starts to seriously lags behind C++ when you need good control over the memory layout of your data. In java you can't have an array of objects, you get an array with references to objects. There are no elegant ways to solve that problem, the language just lacks the proper tools to do it elegantly. Memory layout is of course vital for cache efficiency, so that can give C & C++ a big advantage over java. Since this benchmarks uses arrays of doubles, this isn't an issue.
The problem is that their Java program is just a single static method.
Their Java program is not written as Java.