The Computer Language
Benchmarks Game

Java versus C++ g++ fastest programs

Always look at the source code.

These are only the fastest programs. Do some of them use manually vectorized SIMD? Look at the other programs. They may seem more-like a fair comparison to you.

pidigits
source secs mem gz busy cpu load
Java 0.93 36,088 764 0.97 4% 0% 1% 99%
C++ g++ 0.66 5,152 986 2.63 100% 100% 100% 100%
fasta
source secs mem gz busy cpu load
Java 1.19 44,740 2543 3.50 75% 63% 87% 70%
C++ g++ 0.77 2,504 2751 1.52 64% 0% 99% 37%
spectral-norm
source secs mem gz busy cpu load
Java 1.58 39,408 756 5.97 94% 94% 96% 94%
C++ g++ 0.72 1,192 1044 2.85 99% 99% 100% 100%
k-nucleotide
source secs mem gz busy cpu load
Java 4.85 354,288 1812 15.92 80% 85% 87% 76%
C++ g++ 1.93 156,548 1631 5.88 69% 93% 69% 75%
binary-trees
source secs mem gz busy cpu load
Java 2.48 1,725,776 835 7.86 74% 75% 97% 72%
C++ g++ 0.94 176,428 1122 3.39 86% 88% 100% 85%
reverse-complement
source secs mem gz busy cpu load
Java 1.53 687,864 2183 3.50 80% 46% 57% 46%
C++ g++ 0.52 1,788 1853 0.52 0% 98% 0% 2%
fannkuch-redux
source secs mem gz busy cpu load
Java 10.38 35,388 1282 40.84 99% 99% 98% 97%
C++ g++ 3.29 1,892 1528 13.06 100% 100% 100% 97%
n-body
source secs mem gz busy cpu load
Java 6.77 35,432 1489 6.82 100% 1% 0% 0%
C++ g++ 2.12 764 1927 2.17 0% 2% 100% 0%
regex-redux
source secs mem gz busy cpu load
Java 5.31 793,572 929 17.50 79% 78% 83% 89%
C++ g++ 1.10 203,924 1315 3.43 63% 77% 71% 100%
mandelbrot
source secs mem gz busy cpu load
Java 4.12 70,952 796 16.22 98% 98% 98% 99%
C++ g++ 0.84 34,780 3542 3.27 99% 98% 98% 96%
Java

openjdk 17 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)

C++ g++

g++ (Ubuntu 10.3.0-1ubuntu1) 10.3.0