Ruby 1.9 might just be faster than Python

A

Antonio Cangiano

I ran a micro-benchmark with Ruby 1.8.6, Ruby 1.9 and Python 2.5.1,
and was stunned by Ruby 1.9's improvements. Incidentally for my
particular test (which is a silly one...), Ruby was more than twice as
fast as Python!

http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-python-away/

We can't say for sure yet, but chances are that Ruby 1.9 is going to
be faster than CPython in most situations, which would be a great
accomplishment and step forward for the Ruby community. It's not a
competition, but a speed boost of this caliber is super welcomed. :)

Cheers,
Antonio
 
H

hemant

I ran a micro-benchmark with Ruby 1.8.6, Ruby 1.9 and Python 2.5.1,
and was stunned by Ruby 1.9's improvements. Incidentally for my
particular test (which is a silly one...), Ruby was more than twice as
fast as Python!

http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-python-away/

We can't say for sure yet, but chances are that Ruby 1.9 is going to
be faster than CPython in most situations, which would be a great
accomplishment and step forward for the Ruby community. It's not a
competition, but a speed boost of this caliber is super welcomed. :)


As pointed numerous times on this list, this is perhaps because of
special changes that has went into
Ruby 1.9 for fixed point mathematics ( or integer math as charles tells us )

However, other benchmarks on programming shootout website still show
even Ruby1.9 slower than Python.....

But anyway..we never were mad about performance right?

--
Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org
 
A

Antonio Cangiano

what about python3.0? 5month is not a long time.

Python 3.0 might be faster, but it could just as well be slower. I've
not tested it, but it would be cool to include it in future testing.

Cheers,
Antonio
 
J

Just Another Victim of the Ambient Morality

hemant said:
As pointed numerous times on this list, this is perhaps because of
special changes that has went into
Ruby 1.9 for fixed point mathematics ( or integer math as charles tells
us )

However, other benchmarks on programming shootout website still show
even Ruby1.9 slower than Python.....

But anyway..we never were mad about performance right?

Indeed, as Python moves towards iterators over actual lists, it will
only get faster...
 
M

Marc Heiler

I think what could be more important would be speedups on somewhat
bigger stuff like RoR or some heavy RMagick processing :)

(I wouldnt think pythonistas nor ruby ciders did choose the one or the
other because of speed reasons anyway...)
 
M

MonkeeSage

I ran a micro-benchmark with Ruby 1.8.6, Ruby 1.9 and Python 2.5.1,
and was stunned by Ruby 1.9's improvements. Incidentally for my
particular test (which is a silly one...), Ruby was more than twice as
fast as Python!

http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-pyth...

We can't say for sure yet, but chances are that Ruby 1.9 is going to
be faster than CPython in most situations, which would be a great
accomplishment and step forward for the Ruby community. It's not a
competition, but a speed boost of this caliber is super welcomed. :)

Cheers,
Antonio

I'm also pleased to see how well 1.9 is advancing. :) But it is still
possible to be faster. Here's another silly micro-benchmark...

==== bench.rb ====
require 'benchmark'

def test(n)
n.times {
h = Hash.new
a = %w{a b c d e f g h i j k l m n
o p q r s t u v w x y z}
a.each { |l| h[l] = l.upcase }
p = []
h.each { |k,v| p << [k, v] }
p.each { |p1,p2| h.delete(p1) }
}
end

Benchmark.bm { | x |
x.report { test(100000) }
}
==================

==== bench.py ====
from cProfile import run

def test(n):
for i in xrange(n):
h = dict()
a = 'a b c d e f g h i j k l m n ' \
'o p q r s t u v w x y z'
for l in a.split():
h[l] = l.upper()
p = []
for k, v in h.items():
p.append([k, v])
for p1, p2 in p:
del h[p1]

run('test(100000)')
==================

Results:

$ ruby -v && ruby bench.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
user system total real
24.340000 1.920000 26.260000 ( 28.686532)

$ ruby19 -v && ruby19 bench.rb
ruby 1.9.0 (2007-10-15 patchlevel 0) [i686-linux]
user system total real
17.570000 0.050000 17.620000 ( 19.293883)

$ python -V && python bench.py
Python 2.5.1
5400003 function calls in 14.798 CPU seconds

Ordered by: standard name

ncalls tottime percall cumtime percall
filename:lineno(function)
1 0.000 0.000 14.798 14.798 <string>:1(<module>)
1 11.015 11.015 14.798 14.798 bench.py:3(test)
2600000 1.447 0.000 1.447 0.000 {method 'append' of
'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of
'_lsprof.Profiler' objects}
100000 0.279 0.000 0.279 0.000 {method 'items' of
'dict' objects}
100000 0.509 0.000 0.509 0.000 {method 'split' of 'str'
objects}
2600000 1.548 0.000 1.548 0.000 {method 'upper' of 'str'
objects}

So 1.8.6 comes it at 28.686532 seconds.
Version 1.9 shows a 33% improvement at 19.293883.
But python still takes the cake at 14.798 (49% improvement).

But like others have said, people don't use ruby because it's the
fastest language in the world. A beautiful person may be stupid, and a
smart person may be ugly; but no one ever asked to paint a portrait of
an ugly person, no matter how smart they were. ;) Still, the fact that
current ruby 1.9 performed within 16% of python in this bechmark is
nice.

Regards,
Jordan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top