# 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.

## Benchmark methodology

• 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 5.10.16.3-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 8.56.0.21-CA-linux64) (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (Zulu 8.56.0.21-CA-linux64) (build 25.302-b08, mixed mode)
• C compiler:
Target: x86_64-linux-gnu
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
• JVM options:

• -XX:+UseParallelGC for the parallel garbage collector (GC) that uses multiple threads to speed up GC
• -XX:+UseG1GC for the low latency GC included in recent versions of Java
• C compiler options:

• The code was compiled with -O3 -funroll-loops -Wall -pedantic -ansi.
• Benchmark:

• 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.

## Results

• 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):

FFT SOR MC Sparse LU Composite
Java 8 1368.569 1322.550 891.4420 2072.285 5420.678 2215.105
Java 11 1393.720 1411.172 894.0398 2214.990 5920.144 2366.813
Java 17 1375.584 1412.206 898.1529 2201.966 6169.256 2411.433
C 1996.210 1534.200 770.6100 2725.570 5793.160 2563.950

• For the large benchmark the results are as follows (Mflops, again not reported the slower G1 GC):
FFT SOR MC Sparse LU Composite
Java 8 300.0132 1181.449 896.6529 2216.450 6055.445 2130.002
Java 11 264.6575 1262.190 897.0275 2233.979 6272.665 2186.104
Java 17 298.7562 1273.726 897.0275 2215.252 6287.455 2194.443
C 303.9000 1361.680 774.4600 2411.830 4573.750 1885.124

## 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.