The Computer Language
Benchmarks Game

Ruby versus Python 3 fastest programs

Back in April 2010, Russ Cox charitably suggested that only fannkuch-redux, fasta, k-nucleotide, mandlebrot, nbody, reverse-complement and spectral-norm were close to fair comparisons. As someone who implemented programming languages, his interest was "measuring the quality of the generated code when both compilers are presented with what amounts to the same program."

Differences in approach - to memory management, parallel programming, regex, arbitrary precision arithmetic, implementation technique - don't fit in that kind-of fair comparison — but we still have to deal with them.

These are only the fastest programs. There may be additional measurements for programs which seem more-like a fair comparison to you. Always look at the source code.

spectral-norm
source secs mem gz busy cpu load
Ruby 232.89 18,324 326 274.11 16% 92% 7% 2%
Python 3 645.00 9,476 328 652.53 65% 36% 0% 0%
n-body
source secs mem gz busy cpu load
Ruby 382.36 15,760 1137 429.00 6% 100% 1% 6%
Python 3 857.90 8,160 1196 881.88 25% 76% 1% 1%
binary-trees
source secs mem gz busy cpu load
Ruby 64.75 413,136 1107 221.94 79% 90% 80% 93%
Python 3 80.71 448,276 589 288.85 87% 88% 87% 96%
fasta
source secs mem gz busy cpu load
Ruby 66.96 97,260 1069 106.91 75% 50% 12% 23%
Python 3 66.22 843,344 1947 141.79 87% 13% 47% 66%
fannkuch-redux
source secs mem gz busy cpu load
Ruby 558.13 14,492 1454 2,138.85 100% 95% 97% 92%
Python 3 493.19 47,864 950 1,942.93 98% 100% 100% 96%
regex-redux
source secs mem gz busy cpu load
Ruby 21.68 268,116 751 68.01 94% 86% 70% 63%
Python 3 18.39 453,960 512 36.53 35% 39% 32% 93%
reverse-complement
source secs mem gz busy cpu load
Ruby 24.62 1,605,020 295 45.49 61% 67% 35% 22%
Python 3 16.52 1,004,988 814 22.37 28% 41% 20% 47%
mandelbrot
source secs mem gz busy cpu load
Ruby 444.18 59,864 954 1,774.22 100% 100% 100% 100%
Python 3 258.69 48,416 688 1,033.06 100% 100% 100% 100%
k-nucleotide
source secs mem gz busy cpu load
Ruby 180.88 137,772 667 681.89 98% 99% 89% 91%
Python 3 73.39 217,080 1967 279.23 96% 95% 96% 94%
pidigits
source secs mem gz busy cpu load
Ruby 3.22 328,844 485 7.50 77% 49% 75% 33%
Python 3   Failed
Ruby

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
--jit

Python 3

Python 3.8.0