The Computer Language
25.02 Benchmarks Game

Ruby versus Python 3

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
Ruby #2 154.32 593.14 23,679 1462
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
Ruby 1,437.74 1,436.24 17,695 391
Ruby #8 2,060.21 2,058.52 17,691 418
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
Ruby #3 166.67 166.61—166.69 18,346 1169
Ruby #2 172.30 172.28—172.34 18,043 1143
Ruby #8 320.00 318.33 18,350 1160
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
Ruby #7 768.29 766.83 18,326 1139
spectral-norm      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Ruby #4 126.05 126.09—127.01 20,025 333
Ruby #8 175.57 175.87—176.32 19,132 294
Ruby #5 56.52 207.11—207.67 43,725 764
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
Ruby #5 143.13 566.14 118,436 978
Ruby #4 579.40 578.27 169,955 853
Ruby #2 167.51 660.80 126,730 887
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
Ruby #8 944.53 943.02 50,926 364
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
Ruby #3 1,741.44 1,739.76 50,524 313
Ruby #6   Timed Out  
Ruby #7   Timed Out  
fasta      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Ruby #6 34.17 34.26—34.71 119,271 1097
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
Ruby #3 43.78 43.86—44.10 119,243 1035
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
Ruby #2 82.88 83.00—83.22 143,434 747
Ruby #5 99.47 99.61—100.05 19,194 1000
Ruby #4 129.31 129.79—130.82 305,578 864
Python 3 #8 153.17 153.78—158.43 11,915 738 5.04
Ruby #8 188.42 188.50—189.24 17,822 700
k-nucleotide      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
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
Ruby #7 243.79 246.45—258.00 399,401 792
Ruby #2 262.22 262.46—263.81 179,548 426
Ruby #3 263.08 264.95—272.82 207,466 546
Ruby 87.55 317.80 478,077 583
Ruby #8 519.31 517.57 872,055 529
reverse-complement      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Python 3 #3 4.96 4.95 523,801 803 5.28
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
Ruby #4 6.01 11.72—11.85 3,079,053 608
Python 3 #4 13.47 13.44—13.88 4,109,324 343 5.05
Ruby #5 13.63 13.44—14.87 1,647,829 301
Ruby #3 8.46 16.69—17.00 4,884,902 490
Ruby #2 19.54 19.56—20.02 519,827 272
Ruby 13.29 25.90—26.00 6,528,086 521
binary-trees      [ Contentious. Different approaches. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
Ruby #4 47.09 47.06—47.17 489,144 371
Ruby #2 48.03 48.39—49.02 487,801 385
Ruby 48.14 48.56—49.08 487,592 383
Ruby #3 49.67 50.26—50.90 523,936 407
Ruby #5 18.86 53.95—54.17 2,280,051 1016
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
* Python 3 #3 1.35 1.28—1.32 20,009 573 5.34
Python 3 #4 4.63 4.60 12,718 348 4.88
Ruby 17.94 18.01—18.15 53,740 524
Python 3 #5   Empty  
Ruby #2   Empty  
Ruby #5   Empty  
regex-redux      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* 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
Ruby #2 23.42 23.49—23.62 221,233 444
Ruby #3 12.42 24.39—24.49 217,313 730
Ruby #9 30.77 30.80—30.93 221,237 340
Ruby

ruby 3.4.0dev
(2024-12-25
master f450108330)
+YJIT +PRISM [x86_64-linux]

Python 3

Python 3.13.0