5 ms·
Meh, they dismiss java & pypy very quickly but they don't understand that these languages require warm-up. If you benchmark runs in less than 2 seconds half of
by oelang 11y ago
Meh, they dismiss java & pypy very quickly but they don't understand that these languages require warm-up. If you benchmark runs in less than 2 seconds half of the time measured is starting the runtime, profiling & compiling code. I think that interesting computational problems in economics have a much longer running time.
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.
- nicolapede 11y agoWould you have any reference regarding the performance of java/c++ with respect to manipulation of arrays of doubles? Just curious to know where that 20% comes from.
- oelang 11y agoThe 20% comes from personal experience, maybe I should have said 'close' but that can also mean anything. Basically this is an area where the hotspot heavy duty compiler (C2) does the same optimizations as gcc or llvm. I would say that I would expect gcc & llvm to be within 20% of each other. The 20% is basically different tradeoffs made in the optimization pipeline (different peephole opts, different auto-vectorisation, register allocation algorithm, ...). 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.
- nicolapede 11y agoI see your point now, thanks for the explanation. I mostly do scientific calculations, so effectively manipulations of array of doubles, and I currently mostly use C#. I was under the impression that the performance is similar to C++ (GPU aside), for that the comparison with Java had got my attention.
- cema 11y agoEven though C# is in many ways like Java, it allows (via unsafe blocks and pointers) to better perform memory management. Not sure how widely it is used in practice.
- east2west 11y agoDoes Java have any way of auto vectorization? On modern CPUs SIMD can speed up numerical computation several times easily. However auto vectorization is hard in general, so compilers don't necessarily do a good job and manually optimized code is common. C++ has TMP and libraries such as Eigen use TMP to provide a nice interface to SIMD optimized code. I don't know whether Java has equivalent of compiler intrinsics for SIMD instructions, without which Java code would be far slower for many numerical computation. I believe C# has plans to add an abstraction for SIMD and Mono can already emit SIMD instructions.
- oelang 11y agoIntel recently contributed improved auto-vectorisation for artithmetic to the hotspot compiler. Auto-vectorisation of move instructions has been in hotspot for a few years.
- igouy 11y ago>> If you benchmark runs in less than 2 seconds half of the time measured is starting the runtime, profiling & compiling code.<< 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.
- igouy 11y ago>>half of the time measured is starting the runtime, profiling & compiling code<< 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]
- igouy 11y agoThere is a problem with their representation of Java, and it has nothing to do with "require warm-up". The problem is that their Java program is just a single static method. Their Java program is not written as Java.