Why ruby 1.9 is faster than python 2.7 and 3.2?

18,971

Solution 1

I am a rubyist, and I think you didn't read those (quite old) articles fully. Both admit having used ... "sensationalist" headlines. And that the algorithms they use aren't optimal. So they have little value in my eyes.

The "best" place I know for comparing languages is http://benchmarksgame.alioth.debian.org/. I quote "best" because as others are saying, staging language speed based on a bunch of particular implementations lacks statistical rigor.

That said, if you pitch ruby 1.9 against Python 3, you get these results

The results are: of the 10 tests used, ruby 1.9 is faster than Python in 2 tests. It's similar in 4 and it's slower in the rest (the last example is so bad I'm tempted to call it spurious)

So, according to those 10 different tests, one can only conclude that no, ruby isn't faster than Python in general. (Only in some particular cases).

Solution 2

In addition to remarks of @egarcia and @viraptor, I'd like to note that these benchmarks compare Ruby and CPython, particular python implementation, rather than language. There are much faster python implementations around, like PyPy. And there are different Ruby implementations as well. You cannot compare 'language performance', only specific implementations.

For more info on fast 2.x python - http://speed.pypy.org/

Solution 3

So you pointed at a blog which shows 2 naïve implementation of an algorithm which sucks itself... Then the author compares those two contrived programs and decides that the whole "(runtime environment) smokes (other environment) away".

Not only those benchmarks not prove anything (apart from speed of execution for that specific benchmark), but if you actually looked through the implementation you could find some bit that's more optimised in python, create own benchmark which uses that bit very often and "prove" the opposite result.

Share:
18,971
Eric
Author by

Eric

Updated on June 09, 2022

Comments

  • Eric
    Eric about 2 years

    I read this bunch of links : http://pack.li/L

    ruby 1.9 seems to be 2 times faster than 1.8... and faster than python 2.7 and 3.2

    I made some tests, it is not only on recursion (I knew python was bad about that), put for more standard stuff also.

    So here is my question : How the ruby team have done that ? 2x improvement ? Do they include an JIT compiler/optimizer or something ?

  • Eric
    Eric about 13 years
    do you mean ruby 1.9 should be compared with python/pypy ??
  • Admin
    Admin about 13 years
    @Eric: How many socks are you running?
  • Daniel Kluev
    Daniel Kluev about 13 years
    @Eric I mean 'Ruby 1.9' and 'Python 2.x' or 'Python 3.x' are languages and comparing their performance is nonsense, as performance of language is not defined. Each of these languages has several different implementations, with different performance profiles. For python these are CPython, PyPy, IronPython, Jython, Pyjamas and so on. For Ruby they are CRuby, IronRuby, JRuby, Rubinius and so on. So even if some benchmark would show that CRuby is faster than CPython (which is not the case), it would not mean that Ruby is faster than Python, as there are faster Python implementations avail.
  • Blake
    Blake about 13 years
    So you don't think there are "standard" implementations of Ruby 1.9 and Python3 distributed at well know websites like ruby-lang.org/en/downloads and python.org/download/releases/3.2 ?
  • Daniel Kluev
    Daniel Kluev about 13 years
    @igouy, they are usually called 'reference implementations' rather than 'standard'. Yes, CRuby and CPython are reference implementations for Ruby and Python. So what? Reference implementations are here to define syntax and semantics of the language, not its performance. PyPy or JRuby are no less Python and Ruby accordingly as CPython or Ruby MRI (CRuby). As for 'well-known sites', PyPy is moving to python.org infrastructure and soon(TM) will be available from python.org as well [not that it actually matters, tho].
  • Blake
    Blake about 12 years
    @Daniel Kluev - one year later 'This site hosts the "traditional" implementation of Python (nicknamed CPython)' and PyPy is listed as one of 4 "Alternative Implementations".
  • Blake
    Blake about 12 years
    >>the last example is so bad I'm tempted to call it spurious<< Does no one know how to write a Ruby program that uses GMP? :-)
  • Juan Carlos Coto
    Juan Carlos Coto over 11 years
    Sorry to revive this, but the fact of the matter is, a language cannot have "speed". What is faster, English or Spanish? You might argue in terms of how efficient it is to encode a certain algorithm in it, but nevertheless, that is highly subjective too. Daniel Kluev has it right, by stating that only implementations, not languages, can be benchmarked. One is a construct that enables execution of code written in a language; the other is a theoretical framework to represent algorithms and ideas.