The Computer Language
24.09 Benchmarks Game

Python 3 versus PHP 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
PHP #2 190.06 19,804 447 190.05
PHP #3 56.00 19,804 1166 222.44
PHP #4 56.07 19,804 1168 222.96
PHP 225.15 19,804 488 225.14
Python 3 #6 895.57 19,652 391 895.53
Python 3 #4 291.14 19,652 960 1,150.83
n-body
source secs mem gz cpu secs
PHP #3 66.53 19,804 1088 66.52
Python 3 354.45 19,652 1201 354.43
Python 3 #2 360.53 19,652 1247 360.52
spectral-norm
source secs mem gz cpu secs
PHP 6.87 19,804 1157 27.14
PHP #2 57.15 19,804 403 57.15
PHP #3 16.34 19,804 1214 64.01
Python 3 #7 85.35 19,660 425 338.99
Python 3 #6 343.12 19,660 334 343.11
Python 3 #8 89.19 19,660 415 354.24
mandelbrot
source secs mem gz cpu secs
PHP 87.00 19,804 452 87.00
PHP #3 23.38 48,256 881 93.15
Python 3 #7 158.82 19,652 698 634.14
Python 3 #3 813.16 19,652 319 813.13
Python 3 #2 212.22 102,584 790 846.26
Python 3 #5 247.80 19,652 463 989.79
pidigits
source secs mem gz cpu secs
PHP #5 0.96 19,932 405 0.96
PHP #4 0.98 19,804 396 0.98
PHP #3 0.98 19,804 510 0.98
Python 3 #3 1.33 19,652 573 1.33
PHP #2 1.47 19,932 552 1.47
Python 3 #4 4.61 19,652 348 4.61
PHP 335.40 19,804 756 335.39
Python 3 #5   Failed  
regex-redux
source secs mem gz cpu secs
Python 3 #2 1.35 168,036 1411 2.63
PHP 1.85 194,856 822 3.72
Python 3 8.84 432,748 515 16.23
fasta
source secs mem gz cpu secs
PHP #3 21.15 19,804 1065 21.14
PHP #2 29.41 19,804 1054 29.41
Python 3 #2 37.94 19,652 1126 37.94
Python 3 #3 38.31 19,652 1007 38.30
Python 3 #5 28.13 827,220 1951 55.72
Python 3 57.01 19,652 823 57.01
k-nucleotide
source secs mem gz cpu secs
PHP #4 21.61 260,560 1290 69.80
Python 3 #3 50.62 262,400 1970 193.35
Python 3 #8 73.69 506,368 663 226.37
Python 3 #9 63.78 379,776 614 228.11
Python 3 232.37 499,456 499 231.68
reverse-complement
source secs mem gz cpu secs
Python 3 #3 4.82 508,760 803 4.82
Python 3 #5 4.03 1,500,508 960 7.30
PHP 9.89 1,489,328 323 9.89
Python 3 #2 10.13 1,788,624 440 10.12
Python 3 10.36 1,986,924 484 10.36
Python 3 #6 7.71 2,484,208 821 11.18
PHP #2 11.75 1,787,280 288 11.75
PHP #3 7.75 536,668 452 12.24
Python 3 #4 13.85 4,003,072 343 13.85
binary-trees
source secs mem gz cpu secs
PHP #3 46.07 921,600 434 46.07
PHP #7 15.58 948,608 767 56.00
PHP #4 18.34 918,528 786 56.94
PHP 61.97 748,788 457 61.97
PHP #2 63.25 748,792 429 63.24
PHP #5 33.17 805,512 1048 84.83
PHP #6 27.48 805,532 877 91.38
Python 3 #2 105.82 272,384 344 105.81
Python 3 #5 34.55 274,944 669 123.08
Python 3 35.50 277,632 597 126.38
Python 3 #4 34.68 277,504 481 127.31
Python 3 #3 49.75 672,384 1247 143.18
Python 3

Python 3.12.3

PHP

PHP 8.3.11 (cli)
(built: Sep 5 2024 12:34:23) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11,
with Zend OPcache v8.3.11,
Copyright (c) Zend Technologies