The Computer Language
24.11 Benchmarks Game

C++ g++ versus Java 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
source secs mem gz cpu secs
* C++ g++ #6 3.31 19,760 1535 13.11
* C++ g++ #7 14.03 19,760 1156 14.03
C++ g++ #5 7.85 19,760 987 30.68
C++ g++ #4 8.92 19,760 1445 35.00
C++ g++ #2 9.13 19,760 1446 35.73
C++ g++ #3 37.88 19,760 600 37.87
Java #3 39.96 44,308 1264 40.06
C++ g++ 10.49 19,760 1065 41.21
Java 10.85 44,612 1289 42.80
Java #2 45.77 42,552 520 45.83
Java #8 45.90 42,568 517 45.97
n-body
source secs mem gz cpu secs
* C++ g++ #0 2.15 19,760 1933 2.15
* C++ g++ #7 4.11 19,760 1815 4.11
C++ g++ #9 5.14 19,760 1536 5.14
C++ g++ #3 5.32 19,760 1402 5.32
* C++ g++ #4 5.45 19,760 1434 5.45
* C++ g++ #2 6.02 19,352 1524 6.01
C++ g++ #5 6.32 19,760 1544 6.32
C++ g++ 6.61 19,760 1666 6.61
Java #4 6.88 42,028 1495 6.91
C++ g++ #6 6.93 19,760 1674 6.93
Java #5 7.30 43,424 1435 7.36
Java #2 7.48 42,260 1430 7.52
Java #3 7.49 42,292 1436 7.52
Java #8 7.59 42,924 1322 7.64
Java 7.84 42,652 1437 7.88
spectral-norm
source secs mem gz cpu secs
* C++ g++ #6 0.73 19,760 1050 2.86
* C++ g++ #5 1.33 19,760 1050 5.28
C++ g++ 5.33 19,760 459 5.33
Java #8 5.43 43,368 453 5.49
Java #3 1.57 44,160 762 5.93
C++ g++ #7 1.52 19,512 1284 6.04
Java #2 1.61 43,028 956 6.08
mandelbrot
source secs mem gz cpu secs
* C++ g++ #4 0.89 35,344 3554 3.45
* C++ g++ 0.89 34,952 1797 3.47
* C++ g++ #6 0.98 35,080 1014 3.87
C++ g++ #0 2.35 35,476 2752 9.30
* C++ g++ #7 4.86 35,176 749 13.28
C++ g++ #5 13.44 34,636 596 13.43
C++ g++ #9 3.52 35,120 732 13.55
Java #2 4.08 82,216 802 16.06
Java #4 4.41 105,000 667 16.14
Java #6 4.19 82,232 808 16.42
C++ g++ #2 16.95 34,636 700 16.94
Java 24.50 42,272 671 24.57
C++ g++ #3 27.37 19,760 421 27.36
Java #3 6.96 82,972 910 27.54
Java #8 27.67 45,844 441 27.79
fasta
source secs mem gz cpu secs
C++ g++ #9 0.78 19,352 2758 1.54
C++ g++ #2 1.84 19,760 1129 1.84
C++ g++ 1.92 19,760 1064 1.92
C++ g++ #3 2.63 19,760 1311 2.63
C++ g++ #7 0.87 19,760 2711 3.05
C++ g++ #4 3.32 19,760 1291 3.32
Java #4 3.28 44,352 1528 3.40
C++ g++ #5 1.06 19,760 2345 3.66
Java #6 1.16 49,848 2549 3.71
C++ g++ #6 1.07 19,760 2326 4.01
Java #5 1.24 49,640 2478 4.13
Java #2 4.45 48,896 1259 4.60
Java #8 10.12 182,140 894 10.66
k-nucleotide
source secs mem gz cpu secs
C++ g++ #2 2.01 156,592 1634 5.98
C++ g++ #3 4.19 165,580 1280 13.94
C++ g++ 6.96 757,156 1452 14.75
Java 4.92 427,448 1821 15.77
Java #6 7.27 426,032 1614 25.17
Java #3 7.34 426,540 1642 25.47
Java #4 34.33 197,748 1887 34.67
Java #5 22.10 222,396 2225 48.14
Java #8 81.36 1,559,968 786 83.57
reverse-complement
source secs mem gz cpu secs
* C++ g++ #2 0.74 499,916 2099 0.74
Java #6 3.15 2,032,996 760 3.79
C++ g++ #6 3.30 1,517,824 1827 4.38
Java #5 4.72 1,097,732 1115 4.84
Java #4 5.65 1,891,656 656 5.77
Java #7 23.98 1,037,708 1654 6.26
C++ g++ 6.52 980,156 599 6.51
C++ g++ #5 37.59 771,632 704 37.58
Java #3   Bad Output  
C++ g++ #3   Bad Output  
binary-trees
source secs mem gz cpu secs
C++ g++ #7 0.97 201,512 896 3.40
C++ g++ #5 1.16 200,724 891 4.10
C++ g++ #9 1.74 136,120 815 4.63
C++ g++ #3 1.91 265,636 951 4.74
C++ g++ #6 1.91 266,120 851 4.77
Java #4 4.41 1,821,244 846 5.14
C++ g++ #4 2.22 266,136 826 5.20
Java #6 4.87 1,782,568 535 5.63
Java #3 4.85 1,769,500 546 5.65
Java #2 5.09 1,820,068 558 5.83
Java #8 6.57 1,767,108 596 7.29
Java #7 2.62 1,803,192 841 8.14
C++ g++ 2.65 2,153,044 760 9.23
C++ g++ #2 22.83 265,840 514 22.82
pidigits
source secs mem gz cpu secs
C++ g++ #4 0.71 19,760 521 0.71
* C++ g++ #5 0.73 19,760 804 0.73
* Java #3 0.80 41,900 770 0.83
* Java #2 1.29 45,768 944 1.37
Java 7.68 482,056 807 8.75
regex-redux
source secs mem gz cpu secs
C++ g++ #6 1.15 276,336 2856 2.24
Java #2 1.55 372,764 2201 3.16
Java 8.47 575,552 875 16.69
Java #6 5.60 1,237,440 746 17.12
Java #3 5.25 611,476 935 17.25
C++ g++ #3 12.38 215,640 859 17.95
C++ g++   Make Error  
C++ g++ #2   Make Error  
C++ g++ #5   Make Error  
C++ g++ #4   Make Error  
C++ g++

g++ (Ubuntu 14.2.0-4ubuntu2) 14.2.0

Java

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