How fast is Java 17 for number crunching?
Java 17 is the latest long-term support (LTS) release of standard Java and delivers many performance, stability, and security updates. This article is about a performance comparison benchmark for number crunching between Java 17 and the previous LTS versions Java 11 and Java 8. We also report performance figures for C that is known for being one of the fastest languages for number crunching.
We run the SciMark 2.0 Java benchmark for scientific and numerical computing from the National Institute of Standards and Technology (NIST). It executes and measures five different computational kernels including Fast Fourier Transform (FFT), Jacobi Successive Over-relaxation (SOR), Monte Carlo (MC) integration, Sparse matrix multiply, and dense LU matrix factorization. It also includes two versions. In the small version the problem sizes are chosen to be small in order to focus on internal Java Virtual Machine (JVM) and CPU issues. The large version uses bigger data sizes and is useful in measuring the capability of the memory subsystem of the JVM.
Hardware: Intel® Core™ i7-7700HQ CPU @ 2.80GHz, (4 Cores, 8 Logical Processors) machine with 32 GB of memory
Operating system: Ubuntu 20.04.1 LTS (GNU/Linux 188.8.131.52-microsoft-standard-WSL2 x86_64) without computational demanding processes running
Java Development Kit (JDK):
openjdk version "17" 2021-09-14 LTS OpenJDK Runtime Environment Zulu17.28+13-CA (build 17+35-LTS) OpenJDK 64-Bit Server VM Zulu17.28+13-CA (build 17+35-LTS, mixed mode, sharing)
openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode)
openjdk version "1.8.0_302" OpenJDK Runtime Environment (Zulu 184.108.40.206-CA-linux64) (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (Zulu 220.127.116.11-CA-linux64) (build 25.302-b08, mixed mode)
- C compiler:
Target: x86_64-linux-gnu Thread model: posix gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
-XX:+UseParallelGCfor the parallel garbage collector (GC) that uses multiple threads to speed up GC
-XX:+UseG1GCfor the low latency GC included in recent versions of Java
C compiler options:
- The code was compiled with
-O3 -funroll-loops -Wall -pedantic -ansi.
- The code was compiled with
- Reported are approximate Mflops (Millions of floating point operations per second). Higher is better.
- Each JDK and each GC combination and the C code is run 50 times sequentially for the small and the large benchmark with a pause of 30 seconds between each run.
- As recommended by NIST we report the highest SciMark numbers over the 50 runs.
- The composite figure is the average of the five different computational kernels.
The code can be found on Github.
For both Java 11 and Java 17 the parallel GC was faster than the G1: 9.3% for the small and 3.9% for the large benchmark with Java 11 and 12.6% for the small and 3.3% for the large benchmark with Java 17.
For the small benchmark the results are as follows (Mflops, not reported the slower G1 GC):
- For the large benchmark the results are as follows (Mflops, again not reported the slower G1 GC):
Summary and conclusion
For number crunching with Java 17 the parallel GC is faster than the G1 (default).
Java 17 outperforms both Java 11 and Java 8 on the majority of computational kernels.
Overall Java 17 is faster than Java 11 and Java 8.
Java 17 is almost on par with C on the smaller problem sizes and overall faster on the large benchmark.
It’s time to move your applications to Java 17.
Is Java slow? Compared to C, it’s faster than you think.