4 ms·
Java is faster than C in its second run, prove me wrong
- Osiris-Team 2y agoFeel free to create a PR on the linked repo and prove me wrong. To add some detail: I think that 99% of algorithms are faster in Java in their second run than in any other Language due to the better JIT compiler and optimizations that are possible. I am talking about the GraalVM distribution of Java and its latest version, but we might as well use other distros.
- igouy 2y agoAs that's what interests you, take a look at JMH with GraalVM like this-- https://sgitario.github.io/graalvm-getting-started/ https://sgitario.github.io/graalvm-getting-started/ https://github.com/openjdk/jmh/ https://github.com/openjdk/jmh/
- evanjrowley 2y ago>A repo dedicated to showing why Java is better than all other languages >0 stars The premise of the JIT compiler and optimizations leading to faster execution seems plausible. It's not the first time I've heard it either. I just thought the above two things were humorous. ;)
- Osiris-Team 2y agoI just now created the repo for this purpose, hoped to reach some more experience C developers with it and prove me wrong.
- igouy 2y ago? Fastest implementation: c_clang with 14.51 ms (0.0145 s).
- Osiris-Team 2y agoYeah I proved myself wrong after adding more compiler optimizations.
- floxy 2y agoYour upper limit (1000000) needs to come from runtime (user input/file), otherwise you could create a C++ template program to compute the answer at compile time. Also, you might be interested in the Benchmarks Game: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/gpp-graalvm.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... ...where it looks like GCC C++ beats GraalVM in all the tests.
- Osiris-Team 2y agoDo they compare the second run of Java? Because using GraalVM native image does not really benefit from runtime info and optimization.
- floxy 2y agoI know there was a lot of teeth gnashing in the past about HotSpot warmup, and I think it mostly boiled down to not much of a difference for most tests.
- igouy 2y agoFastest JMH after startup & warmup https://benchmarksgame-team.pages.debian.net/benchmarksgame/sometimes-people-just-make-up-stuff.html#jvm-startup-time https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- igouy 2y agoVarious things. 3,000th run of Java HotSpot. https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/startup.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- SleepyMyroslav 2y ago1BRC was quite fun read. Author really needs better benchmark if they want to get PR out of it =)
- floxy 2y agoAlso countPrimes() is side-effect free, and the value isn't used. So I wouldn't be surprised that at a high enough optimization level, that neither instance of countPrimes() is called for C or C++.
- Osiris-Team 2y agoYeah, feel free to contribute / create a PR with a more C/C++ suited algorithm.
- beardyw 2y agoThis is about the optimising of logic, not languages. At the bottom there are the same instructions which know nothing of the language that conjured them up. Hats off to whoever did the work on this, but let's not get confused about where the magic happens.
- Osiris-Team 2y agoTrue but let's also not forget the unpredictability of stupidity in human developers which probably cause the majority of performance loss in any language.
- Osiris-Team 2y agoI added some further optimizations and guess I was wrong!