The Computer Language
25.01 Benchmarks Game

Java versus C++ g++ fastest performance

How the programs are written matters! Always look at the source code.

If the fastest programs are * hand-written vector instructions, does the host language matter? You might be more interested in the less optimised programs — more seconds, less gz source code.

fannkuch-redux
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #6 3.33 5,800 1535 13.12
* C++ g++ #7 14.06 2,449 1156 14.04—14.11
C++ g++ #5 7.86 5,792 987 30.74—30.81
C++ g++ #4 8.91 5,710 1445 35.02—35.44
C++ g++ #2 9.14 5,698 1446 35.90—36.24
Java #3 38.64 61,968 1264 40.13—41.03
C++ g++ #3 37.89 2,351 600 37.91—37.98
C++ g++ 10.53 5,534 1065 41.27—41.53
Java 10.87 62,976 1289 43.03—43.87
Java #8 44.98 60,264 517 46.66—52.75
Java #2 45.71 60,203 520 48.13—55.01
n-body
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #0 2.15 2,417 1933 2.16
* C++ g++ #7 4.09 5,124 1815 4.13—4.16
C++ g++ #9 5.15 2,486 1536 5.17
C++ g++ #3 5.33 2,482 1402 5.34
* C++ g++ #4 5.46 2,482 1434 5.46
* C++ g++ #2 6.02 2,490 1524 6.02—6.10
C++ g++ #5 6.33 2,478 1544 6.35
C++ g++ 6.62 2,499 1666 6.64
Java #4 6.92 60,592 1495 6.93
C++ g++ #6 6.94 2,499 1674 6.94—6.97
Java #5 7.35 61,727 1435 7.40
Java #2 7.51 60,969 1430 7.53
Java #3 7.54 60,903 1436 7.55
Java #8 7.61 61,170 1322 7.63—7.75
Java 7.89 61,268 1437 7.91
spectral-norm
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #6 0.72 3,981 1050 2.86
* C++ g++ #5 1.33 5,820 1050 5.28
C++ g++ 5.34 5,292 459 5.34
Java #8 5.48 62,124 453 5.52
Java #3 1.63 62,898 762 6.02
C++ g++ #7 1.53 4,071 1284 6.07
Java #2 1.65 62,132 956 6.18—6.22
mandelbrot
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #4 0.89 37,941 3554 3.46
* C++ g++ 0.90 37,626 1797 3.48
* C++ g++ #6 0.98 37,908 1014 3.87
C++ g++ #0 2.36 38,281 2752 9.31
* C++ g++ #7 4.87 38,048 749 13.30
C++ g++ #5 13.47 36,884 596 13.49
C++ g++ #9 3.53 37,863 732 13.59
Java #4 4.40 124,809 667 16.08—16.16
Java #2 4.13 100,966 802 16.25—16.45
Java #6 4.20 100,753 808 16.65—16.86
C++ g++ #2 16.96 36,704 700 16.96
Java 24.56 60,998 671 24.65—24.78
C++ g++ #3 27.38 5,181 421 27.38
Java #8 27.73 64,295 441 27.87—27.92
Java #3 7.10 101,376 910 32.70—36.60
fasta
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #9 0.78 6,214 2758 1.56
C++ g++ #2 1.85 5,108 1129 1.85
C++ g++ 1.93 5,104 1064 1.93
C++ g++ #3 2.63 5,284 1311 2.63
C++ g++ #7 0.88 6,304 2711 3.06
C++ g++ #4 3.34 2,363 1291 3.34
Java #4 3.32 62,714 1528 3.42
C++ g++ #5 1.07 7,012 2345 3.69—3.73
Java #6 1.20 68,497 2549 3.73
C++ g++ #6 1.08 7,127 2326 3.90
Java #5 1.28 68,518 2478 4.11—4.21
Java #2 4.43 64,213 1259 4.66—4.73
Java #8 10.26 200,471 894 11.02—11.14
k-nucleotide
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #2 2.02 162,349 1634 6.08—6.51
C++ g++ #3 4.19 171,622 1280 13.87—14.40
C++ g++ 7.04 778,510 1452 15.20—15.66
Java 5.08 396,227 1821 16.73—17.38
Java #6 7.32 389,710 1614 25.54—26.50
Java #3 7.38 440,680 1642 25.45—26.09
Java #4 34.62 218,296 1887 35.14—36.03
Java #5 20.66 248,066 2225 45.27—46.83
Java #8 80.82 1,195,364 786 84.30—87.87
reverse-complement
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #2 0.76 514,101 2099 0.76
Java #6 3.22 2,103,075 760 3.88
Java #5 4.81 1,143,542 1115 4.94—5.03
Java #4 5.81 1,956,385 656 5.94
C++ g++ 6.55 1,006,805 599 6.55—6.67
C++ g++ #5 37.66 792,846 704 37.65—37.69
Java #7   Bad Output  
Java #3   Bad Output  
C++ g++ #6   Bad Output  
C++ g++ #3   Bad Output  
binary-trees
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #7 1.01 175,108 896 3.47—3.61
C++ g++ #5 1.17 208,171 891 4.13—4.16
C++ g++ #9 1.76 140,571 815 4.67—4.81
C++ g++ #6 1.93 273,973 851 4.91—5.08
C++ g++ #3 2.28 273,715 951 5.06—5.10
C++ g++ #4 2.22 273,977 826 5.21—5.32
Java #4 4.50 1,774,043 846 5.65—5.96
Java #6 4.91 1,700,258 535 5.69—5.77
Java #3 4.89 1,627,595 546 5.71—5.82
Java #2 5.12 1,663,476 558 5.93—5.99
Java #8 6.53 1,673,216 596 7.30—7.39
Java #7 2.63 1,786,659 841 8.14—8.22
C++ g++ 2.69 1,896,727 760 9.44—9.51
C++ g++ #2 22.77 274,080 514 22.83—23.04
pidigits
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #4 0.72 6,496 521 0.72
* C++ g++ #5 0.73 6,300 804 0.73
* Java #3 0.84 60,449 770 0.85
* Java #2 1.33 64,856 944 1.39
Java 7.72 423,014 807 8.77—8.80
regex-redux
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #6 1.14 285,639 2856 2.25
Java 8.49 533,643 875 16.77—16.97
Java #3 5.30 652,009 935 17.10—17.22
Java #6 5.67 1,285,243 746 17.18—17.43
C++ g++ #3 12.37 222,614 859 18.07—18.64
C++ g++   Empty  
Java #2   Bad Output  
C++ g++ #2   Empty  
C++ g++ #5   Empty  
C++ g++ #4   Empty  
Java

java 23 2024-09-17
Java HotSpot(TM) 64-Bit Server VM
(build 23+37-2369,
mixed mode, sharing)

C++ g++

g++ (Ubuntu 14.2.0-4ubuntu2) 14.2.0