The Computer Language
25.01 Benchmarks Game

Python 3 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
C++ g++ #3 37.89 2,351 600 37.91—37.98
C++ g++ 10.53 5,534 1065 41.27—41.53
Python 3 #6 943.88 11,874 391 942.63
Python 3 #4 311.18 28,701 960 1,221.85
Python 3 #8 2,457.09 11,874 414 2,455.59
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
C++ g++ #6 6.94 2,499 1674 6.94—6.97
Python 3 372.41 12,198 1201 371.23
Python 3 #2 442.06 12,554 1247 440.87
Python 3 #8 529.38 12,497 1172 528.16
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
C++ g++ #7 1.53 4,071 1284 6.07
Python 3 #6 349.68 13,660 334 348.48
Python 3 #4 90.37 34,693 415 352.91
Python 3 #8 386.45 12,833 334 385.07
Python 3 #7 109.91 34,578 425 421.84
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
C++ g++ #2 16.96 36,704 700 16.96
C++ g++ #3 27.38 5,181 421 27.38
Python 3 #7 182.94 62,173 698 723.28
Python 3 #3 879.41 45,085 319 877.96
Python 3 #2 237.64 230,973 790 937.87
Python 3 #5 260.63 61,620 463 1,033.16
Python 3 #8 1,577.29 45,031 379 1,575.80
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
C++ g++ #5 1.07 7,012 2345 3.69—3.73
C++ g++ #6 1.08 7,127 2326 3.90
Python 3 #3 39.03 12,218 1007 38.87—47.23
Python 3 #2 39.06 12,415 1126 39.10—46.32
Python 3 #5 27.95 1,190,347 1951 54.25—54.92
Python 3 57.39 12,100 823 57.48—65.23
Python 3 #8 153.17 11,915 738 154.06—158.15
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
Python 3 #3 46.55 674,185 1970 182.63—187.07
Python 3 #4 76.67 523,751 663 233.38—238.93
Python 3 #8 234.08 642,265 525 235.45—236.80
Python 3 234.20 515,047 499 235.22—237.04
Python 3 #9 66.67 392,184 614 236.55—238.32
reverse-complement
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
* C++ g++ #2 0.76 514,101 2099 0.76
Python 3 #3 4.96 523,801 803 4.95
C++ g++ 6.55 1,006,805 599 6.55—6.67
Python 3 #5 4.18 2,418,156 960 7.46—7.50
Python 3 #2 10.09 1,837,285 440 10.14—10.23
Python 3 10.43 2,040,713 484 10.44—10.58
Python 3 #6 7.59 2,795,930 821 11.07—11.11
Python 3 #4 13.47 4,109,324 343 13.47—13.85
C++ g++ #5 37.66 792,846 704 37.65—37.69
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
C++ g++ 2.69 1,896,727 760 9.44—9.51
C++ g++ #2 22.77 274,080 514 22.83—23.04
Python 3 #2 100.49 281,829 344 100.71—101.07
Python 3 #4 33.37 460,771 481 121.34—121.66
Python 3 34.85 445,649 597 123.14—123.93
Python 3 #5 35.37 806,117 669 125.73—126.09
Python 3 #3 51.88 819,077 1247 148.97—149.82
Python 3 #8 560.84 821,846 535 559.59
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
* Python 3 #3 1.35 20,009 573 1.28—1.32
Python 3 #4 4.63 12,718 348 4.60
Python 3 #5   Empty  
regex-redux
  elapsed     Mean or 95% CI
source secs mem gz cpu secs
C++ g++ #6 1.14 285,639 2856 2.25
* Python 3 #2 1.41 191,300 1411 2.65
Python 3 8.96 459,624 515 16.49—16.73
C++ g++ #3 12.37 222,614 859 18.07—18.64
C++ g++   Empty  
C++ g++ #2   Empty  
C++ g++ #5   Empty  
C++ g++ #4   Empty  
Python 3

Python 3.13.0

C++ g++

g++ (Ubuntu 14.2.0-4ubuntu2) 14.2.0