The Computer Language
Benchmarks Game

C++ g++ versus Java 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.

regex-redux
source secs mem gz busy cpu load
C++ g++ 1.10 203,924 1315 3.43 63% 77% 71% 100%
Java 5.58 985,696 929 18.26 81% 77% 84% 85%
mandelbrot
source secs mem gz busy cpu load
C++ g++ 0.84 34,780 3542 3.27 99% 98% 98% 96%
Java 4.15 69,136 796 16.29 98% 99% 98% 99%
fannkuch-redux
source secs mem gz busy cpu load
C++ g++ 3.29 1,892 1528 13.06 100% 100% 100% 97%
Java 10.64 35,192 1282 41.91 99% 98% 99% 97%
n-body
source secs mem gz busy cpu load
C++ g++ 2.12 764 1927 2.17 0% 2% 100% 0%
Java 6.74 35,844 1489 6.82 1% 100% 1% 0%
reverse-complement
source secs mem gz busy cpu load
C++ g++ 0.52 1,788 1853 0.52 0% 98% 0% 2%
Java 1.54 670,924 2183 3.51 46% 56% 48% 79%
binary-trees
source secs mem gz busy cpu load
C++ g++ 0.94 176,428 1122 3.39 86% 88% 100% 85%
Java 2.48 1,722,848 835 7.88 98% 75% 71% 74%
k-nucleotide
source secs mem gz busy cpu load
C++ g++ 1.93 156,548 1631 5.88 69% 93% 69% 75%
Java 4.98 356,904 1812 16.25 78% 76% 96% 76%
spectral-norm
source secs mem gz busy cpu load
C++ g++ 0.72 1,192 1044 2.85 99% 99% 100% 100%
Java 1.63 39,304 756 6.22 95% 97% 95% 95%
fasta
source secs mem gz busy cpu load
C++ g++ 0.77 2,504 2751 1.52 64% 0% 99% 37%
Java 1.21 44,620 2543 3.58 89% 75% 65% 68%
pidigits
source secs mem gz busy cpu load
C++ g++ 0.66 5,152 986 2.63 100% 100% 100% 100%
Java 0.93 36,552 764 0.98 2% 3% 1% 99%
C++ g++

g++ (Ubuntu 10.3.0-1ubuntu1) 10.3.0

Java

openjdk 16 2021-03-16
OpenJDK Runtime Environment (build 16+36-2231)
OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)