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 ?
There is a perception that Python is faster than Ruby, and this has often led teams to prefer it over Ruby for web development. The Ruby community is painfully aware of this, and Ruby has gotten way faster over the years. Now, in benchmarks, Ruby performs just about as well as Python, if not better.
each should be faster than map since the former does not modify/create anything while the latter does. But in your code, you are comparing different things. It is push that is taking time. Your code is irrelevant from comparing each and map .
Ruby is simpler hence faster than Java. The code written in Ruby changes on the fly, while its competitor needs to generate the byte code before it can run.
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).
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With