Categories
All articles

Python and Ruby Performance

by: Carl Johansson Published 9/03 - 2007

Is Python significantly faster than Ruby? The Computer Language Shootout says so. We’re working on setting up a small test suite of the type of computing we will need to do in our application, so we can do a fair benchmarking.

We’re also looking at what options are available to improve the performance. Ruby is waiting for YARV, which Antonio Cangiano recently benchmarked, and it looks very promising. Python has psyco, pypy, and several other options. Being able to integrate code written in other languages to optimize when really necessary is important, and both languages seem to have good support.

Has anybody else done customized benchmarking of these two languages for a specific web application?




Related Posts

  • Pablo

    The benchmark results alone are a insightful element when choosing the right language for the job. My choice here is Python 2.5, for speed.

  • Luis

    I’m a Python fan with no experience with Ruby, and I’m glad that Python benchmarks well against other dynamic languages.
    However, and to be honest, if speed is an important factor when choosing a language, perhaps none of these is the right choice (at this moment).

    I think that in 90% (or more) of the cases, dynamic languages speed is more than enough.
    In those few cases where top speed is needed, C is the choice.

    When you need top speed, you will probably have to resort to C or write a c extension (no matter if you are using python, ruby or any other langauge).
    But if you don’t need the speed of C, it doesn’t really matter if you are using Python or Ruby. Any of these will be fast enough.

    That being said, be adviced that the Pypy project (python writen in python) is a very ambicious project with many goals.
    One of them is, of course, speeding up python. But the interesting thing is that the infraestructure and tools supplied by that project may be used to implement any other dynamic language very easily.
    People are writing already javascript, logo, scheme and many other front-ends in pypy, so chances are that sooner or later, someone will come up with a ruby implementation, and this implementation will enjoy all the advantages and capabilities of the python version.

    Isn’t that cool?

  • Ventrix

    I totally agree with Luis. If speed doesn’t matter, then the appropriate language is the one the programmer knows better…

  • roger

    Yeah Python is faster–especially with Psycho. But if you’re willing to live with the 3-6x slowdown, it doesn’t matter.

  • Tomáš Holas

    I did an almost-real word test Ruby(both versions) vs. Python:
    http://railstooge.blogspot.com/2009/01/ruby-vs-python-lame-benchmark.html

  • http://twitter.com/ygbr Ygor Lemos

    You really should take Google’s Pyhton Implementation ( Unladen Swallow ) into consideration… They are rewriting great part of Python’s code and main modules in C, optimizing the whole language for performance improvements.
    Guido van Rossum ( Python’s Creator ) is involved in the project and the speed improvements are really impressive ( taking Python far above any of the results gathered on benchmarks tests performed in many places )
    Also, you should consider Python 3.1 for the tests as many improvements in IO and many other parts of the codebase were rewritten and tend to be really faster than 2.x implementations.
    Overall, if speed is really a concern, go with C, C++, Assembly or any other “lower level” compiled language.

  • theserge

    I inadvertently did a Ruby vs Python benchmark during my benchmarking of InnoDB vs ICE for QPS (queries per second) on a large table (30 mil rows). On InnoDB, Ruby was was giving me a surprisingly slow 6.5k QPS on two threads. Python was doing 37k QPS. My guess is this has more to do with the mysql libraries than anything else. I used MySQLdb on python and “mysql” (the one that comes with Rails 3) on ruby. If you need to serve lots of little queries, def a no brainer. Let me know if you want my scripts.