The Computer Language
Benchmarks Game

Java versus C gcc fastest programs

Back in April 2010, Russ Cox charitably suggested that only fannkuch-redux, fasta, k-nucleotide, mandlebrot, nbody, reverse-complement and spectral-norm were close to fair comparisons. As someone who implemented programming languages, his interest was "measuring the quality of the generated code when both compilers are presented with what amounts to the same program."

Differences in approach - to memory management, parallel programming, regex, arbitrary precision arithmetic, implementation technique - don't fit in that kind-of fair comparison — but we still have to deal with them.

These are only the fastest programs. There may be additional measurements for programs which seem more-like a fair comparison to you. Always look at the source code.

fasta
source secs mem gz busy cpu load
Java 2.22 45,172 2473 5.99 61% 50% 98% 60%
C gcc 1.46 2,992 2268 5.81 99% 99% 99% 99%
k-nucleotide
source secs mem gz busy cpu load
Java 9.33 447,976 1812 29.36 73% 83% 82% 77%
C gcc 6.00 130,132 1506 18.48 70% 95% 89% 53%
fannkuch-redux
source secs mem gz busy cpu load
Java 14.33 34,888 1282 56.56 99% 98% 99% 98%
C gcc 8.75 948 910 34.50 100% 100% 100% 95%
reverse-complement
source secs mem gz busy cpu load
Java 3.16 712,368 2183 7.08 65% 47% 42% 70%
C gcc 1.90 533,424 820 2.58 6% 20% 10% 99%
pidigits
source secs mem gz busy cpu load
Java 3.07 39,320 938 3.31 2% 5% 3% 98%
C gcc 1.75 2,812 452 1.79 100% 0% 2% 1%
spectral-norm
source secs mem gz busy cpu load
Java 4.19 36,680 950 16.31 98% 97% 97% 98%
C gcc 1.98 1,224 569 7.88 99% 99% 99% 100%
binary-trees
source secs mem gz busy cpu load
Java 8.32 953,620 835 28.37 95% 87% 81% 77%
C gcc 3.53 168,844 809 11.76 98% 75% 86% 74%
n-body
source secs mem gz busy cpu load
Java 21.95 35,604 1429 22.75 2% 1% 100% 1%
C gcc 7.30 8 1391 7.37 0% 0% 100% 1%
mandelbrot
source secs mem gz busy cpu load
Java 6.83 79,108 796 26.86 97% 99% 99% 99%
C gcc 1.64 26,504 1135 6.54 100% 100% 99% 100%
regex-redux
source secs mem gz busy cpu load
Java 10.31 644,560 740 31.47 72% 72% 92% 70%
C gcc 1.48 152,188 1397 3.44 46% 45% 100% 41%
Java

openjdk 13 2019-09-17
OpenJDK Runtime Environment (build 13+33)
OpenJDK 64-Bit Server VM (build 13+33, mixed mode, sharing)

C gcc

gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008