The benchmarks here do not try to be complete, as they are showing the performance of the languages in one aspect, and mainly: loops, dynamic arrays with numbers, basic math operations.
Here are the benchmark results:
|Language||CPU time||Slower than||Language
|C++ (optimized with -O2)||0.915||0.058||0.973||–||–||g++ 6.1.1||link|
|Java 8 (non-std lib)||1.120||0.006||1.126||15%||15%||1.8.0_102||link|
|Python 2.7 + PyPy||1.386||0.128||1.514||55%||34%||PyPy 5.4.0||link|
|C++ (not optimized)||2.896||0.058||2.954||203%||7%||g++ 6.1.1||link|
|Java 8 (see notes)||12.123||0.078||12.200||1153%||69%||1.8.0_102||link|
The big difference this time is that we use a slightly modified benchmark method. Programs are no longer limited to just 10 loops. Instead they run for 90 wall-clock seconds, and then we divide and normalize their performance as if they were running for only 10 loops. This way we can compare with the previous results. The benefit of doing the tests like this is that the startup and shutdown times of the interpreters should make almost no difference now. It turned out that the new method doesn’t significantly change the outcome compared to the previous benchmark runs, which is good as the old way of benchmarks seems also correct.
Brief analysis of the results:
- NodeJS version 4.3.x got much slower than the previous major version 4.2.x. This is the only surprise.
- Python and Perl seem a bit slower than before but this is probably due to the fact that C++ performed even better because of the new benchmark method.
- Java 8 didn’t perform much faster as we expected. Maybe it gets slower as more and more loops are done, which also allocated more RAM.
- Also review the analysis in the old 2016 tests for more information.
The tests were run on a Debian Linux 64-bit machine.
You can download the source codes, raw results, and the benchmark batch script at: