The Computer Language
25.03 Benchmarks Game

Python 3 versus C++ g++

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

If the fastest programs are flagged * possible hand-written vector instructions or "unsafe" or naked ffi, 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 cpu secs mem gz make
* C++ g++ #6 3.33 13.12 5,800 1535 4.64
* C++ g++ #7 14.06 14.04—14.11 2,449 1156 2.95
C++ g++ #5 7.86 30.73—30.82 5,792 987 3.67
C++ g++ #4 8.91 34.99—35.47 5,710 1445 12.14
C++ g++ #2 9.14 35.88—36.26 5,698 1446 11.86
C++ g++ #3 37.89 37.90—37.99 2,351 600 2.70
C++ g++ 10.53 41.25—41.55 5,534 1065 3.88
Python 3 #6 943.88 942.63 11,874 391 3.58
Python 3 #4 311.18 1,221.85 28,701 960 5.27
Python 3 #8 2,457.09 2,455.59 11,874 414 5.65
n-body      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C++ g++ #0 2.15 2.16 2,417 1933 3.66
* C++ g++ #7 4.09 4.12—4.17 5,124 1815 4.18
C++ g++ #9 5.15 5.17 2,486 1536 3.03
C++ g++ #3 5.33 5.34 2,482 1402 2.85
* C++ g++ #4 5.46 5.46 2,482 1434 2.83
C++ g++ #2 6.02 6.02—6.10 2,490 1524 3.04
C++ g++ #5 6.33 6.35 2,478 1544 2.92
C++ g++ 6.62 6.64 2,499 1666 3.15
C++ g++ #6 6.94 6.93—6.98 2,499 1674 2.98
Python 3 372.41 371.23 12,198 1201 5.23
Python 3 #2 442.06 440.87 12,554 1247 5.24
Python 3 #8 529.38 528.16 12,497 1172 4.94
spectral-norm      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C++ g++ #6 0.72 2.86 3,981 1050 3.08
* C++ g++ #5 1.33 5.28 5,820 1050 2.86
C++ g++ 5.34 5.34 5,292 459 3.75
C++ g++ #7 1.53 6.07 4,071 1284 2.71
Python 3 #6 349.68 348.48 13,660 334 5.44
Python 3 #4 90.37 352.91 34,693 415 5.41
Python 3 #8 386.45 385.07 12,833 334 5.08
Python 3 #7 109.91 421.84 34,578 425 5.30
mandelbrot      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C++ g++ #4 0.89 3.46 37,941 3554 5.04
* C++ g++ 0.90 3.48 37,626 1797 3.59
* C++ g++ #6 0.98 3.87 37,908 1014 4.36
C++ g++ #0 2.36 9.31 38,281 2752 4.60
C++ g++ #7 4.87 13.30 38,048 749 3.03
C++ g++ #5 13.47 13.49 36,884 596 2.76
C++ g++ #9 3.53 13.59 37,863 732 3.03
C++ g++ #2 16.96 16.96 36,704 700 3.28
C++ g++ #3 27.38 27.38 5,181 421 3.69
Python 3 #7 182.94 723.28 62,173 698 5.52
Python 3 #3 879.41 877.96 45,085 319 5.26
Python 3 #2 237.64 937.87 230,973 790 5.42
Python 3 #5 260.63 1,033.16 61,620 463 5.48
Python 3 #8 1,577.29 1,575.80 45,031 379 4.84
fasta      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C++ g++ #9 0.78 1.56 6,214 2758 6.43
C++ g++ #2 1.85 1.85 5,108 1129 2.89
C++ g++ 1.93 1.93 5,104 1064 2.98
C++ g++ #3 2.63 2.63 5,284 1311 3.33
C++ g++ #7 0.88 3.06 6,304 2711 4.58
C++ g++ #4 3.34 3.34 2,363 1291 3.03
C++ g++ #5 1.07 3.69—3.73 7,012 2345 3.90
C++ g++ #6 1.08 3.90 7,127 2326 3.72
Python 3 #3 39.03 38.30—47.80 12,218 1007 5.32
Python 3 #2 39.06 38.61—46.82 12,415 1126 5.21
Python 3 #5 27.95 54.20—54.96 1,190,347 1951 5.52
Python 3 57.39 56.94—65.76 12,100 823 5.06
Python 3 #8 153.17 153.78—158.43 11,915 738 5.04
k-nucleotide      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C++ g++ #2 2.02 6.05—6.54 162,349 1634 7.41
C++ g++ #3 4.19 13.83—14.44 171,622 1280 5.17
C++ g++ 7.04 15.17—15.69 778,510 1452 6.55
Python 3 #3 46.55 182.32—187.37 674,185 1970 5.68
Python 3 #4 76.67 233.00—239.32 523,751 663 4.89
Python 3 #8 234.08 235.36—236.89 642,265 525 5.15
Python 3 234.20 235.10—237.16 515,047 499 5.34
Python 3 #9 66.67 236.43—238.45 392,184 614 4.09
reverse-complement      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* C++ g++ #2 0.76 0.76 514,101 2099 4.30
Python 3 #3 4.96 4.95 523,801 803 5.28
C++ g++ 6.55 6.55—6.68 1,006,805 599 3.43
Python 3 #5 4.18 7.46—7.50 2,418,156 960 5.36
Python 3 #2 10.09 10.13—10.24 1,837,285 440 5.32
Python 3 10.43 10.43—10.59 2,040,713 484 5.28
Python 3 #6 7.59 11.07—11.11 2,795,930 821 5.37
Python 3 #4 13.47 13.44—13.88 4,109,324 343 5.05
C++ g++ #5 37.66 37.65—37.69 792,846 704 3.40
C++ g++ #6   Bad Output  
C++ g++ #3   Bad Output  
binary-trees      [ Contentious. Different approaches. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C++ g++ #7 1.01 3.46—3.62 175,108 896 7.50
C++ g++ #5 1.17 4.12—4.17 208,171 891 3.87
C++ g++ #9 1.76 4.66—4.82 140,571 815 4.05
C++ g++ #6 1.93 4.90—5.09 273,973 851 4.98
C++ g++ #3 2.28 5.06—5.10 273,715 951 4.79
C++ g++ #4 2.22 5.20—5.33 273,977 826 5.16
C++ g++ 2.69 9.43—9.52 1,896,727 760 5.34
C++ g++ #2 22.77 22.81—23.05 274,080 514 3.52
Python 3 #2 100.49 100.69—101.09 281,829 344 5.08
Python 3 #4 33.37 121.32—121.68 460,771 481 5.57
Python 3 34.85 123.08—123.98 445,649 597 5.16
Python 3 #5 35.37 125.71—126.12 806,117 669 5.30
Python 3 #3 51.88 148.91—149.87 819,077 1247 5.39
pidigits      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C++ g++ #4 0.72 0.72 6,496 521 3.45
* C++ g++ #5 0.73 0.73 6,300 804 3.34
* Python 3 #3 1.35 1.28—1.32 20,009 573 5.34
Python 3 #5 1.40 1.36 15,606 369 7.20
Python 3 #4 4.63 4.60 12,718 348 4.88
regex-redux      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
C++ g++ #6 1.14 2.25 285,639 2856 5.06
* Python 3 #2 1.41 2.65 191,300 1411 5.48
Python 3 8.96 16.47—16.75 459,624 515 5.47
C++ g++ #3 12.37 18.03—18.68 222,614 859 12.29
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