The Computer Language
24.12 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
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
C++ g++ 10.49 19,760 1065 41.21
Python 3 #6 1,033.31 19,312 391 1,033.27
Python 3 #4 302.37 19,312 960 1,196.45
Python 3 #8 2,259.59 19,312 414 2,259.50
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
C++ g++ #6 6.93 19,760 1674 6.93
Python 3 355.06 19,312 1201 355.05
Python 3 #2 374.16 19,312 1247 374.14
Python 3 #8 518.11 19,312 1172 518.09
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
C++ g++ #7 1.52 19,512 1284 6.04
Python 3 #6 347.53 19,316 334 347.52
Python 3 #4 90.52 19,308 415 359.95
Python 3 #8 379.97 19,440 334 379.96
Python 3 #7 97.11 19,316 425 380.79
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
C++ g++ #2 16.95 34,636 700 16.94
C++ g++ #3 27.37 19,760 421 27.36
Python 3 #7 172.20 19,312 698 687.68
Python 3 #3 861.76 19,312 319 861.73
Python 3 #2 235.71 95,164 790 926.30
Python 3 #5 257.00 19,312 463 1,026.96
Python 3 #8 1,528.00 19,364 379 1,527.73
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
C++ g++ #5 1.06 19,760 2345 3.66
C++ g++ #6 1.07 19,760 2326 4.01
Python 3 #2 39.00 19,312 1126 39.00
Python 3 #3 39.12 19,312 1007 39.12
Python 3 #5 27.86 827,284 1951 53.94
Python 3 57.21 19,312 823 57.20
Python 3 #8 156.78 19,780 738 156.35
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
Python 3 #3 50.15 262,368 1970 185.77
Python 3 #4 79.01 506,112 663 236.67
Python 3 238.45 499,072 499 237.78
Python 3 #8 238.78 623,448 525 237.93
Python 3 #9 68.33 379,392 614 238.74
reverse-complement
source secs mem gz cpu secs
* C++ g++ #2 0.74 499,916 2099 0.74
C++ g++ #6 3.30 1,517,824 1827 4.38
Python 3 #3 4.86 507,712 803 4.86
C++ g++ 6.52 980,156 599 6.51
Python 3 #5 4.09 1,500,716 960 7.41
Python 3 #2 10.08 1,788,136 440 10.08
Python 3 10.29 1,986,440 484 10.29
Python 3 #6 7.38 2,484,372 821 10.89
Python 3 #4 13.41 4,002,688 343 13.41
C++ g++ #5 37.59 771,632 704 37.58
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
C++ g++ #4 2.22 266,136 826 5.20
C++ g++ 2.65 2,153,044 760 9.23
C++ g++ #2 22.83 265,840 514 22.82
Python 3 #2 100.90 271,872 344 100.89
Python 3 #4 33.61 276,992 481 121.96
Python 3 #5 35.49 274,816 669 126.17
Python 3 36.12 276,992 597 127.68
Python 3 #3 52.28 671,872 1247 149.07
Python 3 #8 558.92 798,336 535 558.85
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
* Python 3 #3 1.26 19,312 573 1.26
Python 3 #4 4.54 19,312 348 4.54
Python 3 #5   Failed  
regex-redux
source secs mem gz cpu secs
C++ g++ #6 1.15 276,336 2856 2.24
* Python 3 #2 1.35 168,236 1411 2.64
Python 3 8.91 432,220 515 16.44
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  
Python 3

Python 3.13.0

C++ g++

g++ (Ubuntu 14.2.0-4ubuntu2) 14.2.0