# Ruby 1.9 might just be faster than Python

**URL:** <https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569>\
**Category:** ruby-talk\
**Created:** [28 November 2007 10:25 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569 "2007-11-28T10:25:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Cangiano](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Antonio\_Cangiano](https://rubytalk.org/u/Antonio_Cangiano)\
**Post date:** [28 November 2007 10:25 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/1 "2007-11-28T10:25:09Z")

</div>

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!

> **[Holy Shmoly, Ruby 1.9 smokes Python away! - Programming Zen](http://programmingzen.com/holy-shmoly-ruby-19-smokes-python-away/)**
>
> Alright the title of this post is a tad sensational sounding, I know, and it’s in part aimed at messing with my many Pythonista friends. We Rubyists have been teased for a long time, due to the slowness of the main Ruby interpreter. Well, it looks...

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

---

<div class="post-metadata">

**Author:** ![11139](https://avatars.discourse-cdn.com/v4/letter/1/3d9bf3/32.png) [@11139](https://rubytalk.org/u/11139)\
**Post date:** [28 November 2007 10:33 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/2 "2007-11-28T10:33:13Z")

</div>

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

> **···**
>
> --------------------------------------------------  
> From: "Antonio Cangiano" \<acangiano@gmail.com\>  
> Sent: Wednesday, November 28, 2007 6:25 PM  
> Newsgroups: comp.lang.ruby  
> To: "ruby-talk ML" \<ruby-talk@ruby-lang.org\>  
> Subject: Ruby 1.9 might just be faster than Python
> 
> > 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!
> > 
> > [Holy Shmoly, Ruby 1.9 smokes Python away! | Programming Zen](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

---

<div class="post-metadata">

**Author:** ![Hemant\_Kumar](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hemant\_Kumar](https://rubytalk.org/u/Hemant_Kumar)\
**Post date:** [28 November 2007 10:59 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/3 "2007-11-28T10:59:33Z")

</div>

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?

> **···**
>
> On Nov 28, 2007 3:55 PM, Antonio Cangiano \<acangiano@gmail.com\> wrote:
> 
> > 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!
> > 
> > [Holy Shmoly, Ruby 1.9 smokes Python away! | Programming Zen](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. 🙂
> 
> --  
> 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](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![Jordan\_Callicoat](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jordan\_Callicoat](https://rubytalk.org/u/Jordan_Callicoat)\
**Post date:** [28 November 2007 14:25 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/4 "2007-11-28T14:25:00Z")

</div>

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)  
&nbsp;&nbsp;n.times {  
&nbsp;&nbsp;&nbsp;&nbsp;h = Hash.new  
&nbsp;&nbsp;&nbsp;&nbsp;a = %w{a b c d e f g h i j k l m n  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o p q r s t u v w x y z}  
&nbsp;&nbsp;&nbsp;&nbsp;a.each { |l| h[l] = l.upcase }  
&nbsp;&nbsp;&nbsp;&nbsp;p =   
&nbsp;&nbsp;&nbsp;&nbsp;h.each { |k,v| p \<\< [k, v] }  
&nbsp;&nbsp;&nbsp;&nbsp;p.each { |p1,p2| h.delete(p1) }  
&nbsp;&nbsp;}  
end

Benchmark.bm { | x |  
&nbsp;&nbsp;x.report { test(100000) }  
}

> **···**
>
> On Nov 28, 4:24 am, Antonio Cangiano \<acangi...@gmail.com\> wrote:
> 
> > 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\.\.\](http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-pyth%5C.%5C.%5C).
> > 
> > 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
> 
> ==================
> 
> ==== bench.py ====  
> from cProfile import run
> 
> def test(n):  
> &nbsp;&nbsp;for i in xrange(n):  
> &nbsp;&nbsp;&nbsp;&nbsp;h = dict()  
> &nbsp;&nbsp;&nbsp;&nbsp;a = 'a b c d e f g h i j k l m n ' \  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'o p q r s t u v w x y z'  
> &nbsp;&nbsp;&nbsp;&nbsp;for l in a.split():  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h[l] = l.upper()  
> &nbsp;&nbsp;&nbsp;&nbsp;p =   
> &nbsp;&nbsp;&nbsp;&nbsp;for k, v in h.items():  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.append([k, v])  
> &nbsp;&nbsp;&nbsp;&nbsp;for p1, p2 in p:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;del h[p1]
> 
> # run('test(100000)')
> 
> Results:
> 
> $ ruby -v && ruby bench.rb  
> ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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]  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user system total real  
> 17.570000 0.050000 17.620000 ( 19.293883)
> 
> $ python -V && python bench.py  
> Python 2.5.1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5400003 function calls in 14.798 CPU seconds
> 
> &nbsp;&nbsp;&nbsp;Ordered by: standard name
> 
> &nbsp;&nbsp;&nbsp;ncalls tottime percall cumtime percall  
> filename:lineno(function)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 0.000 0.000 14.798 14.798 \<string\>:1(\<module\>)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 11.015 11.015 14.798 14.798 bench.py:3(test)  
> &nbsp;&nbsp;2600000 1.447 0.000 1.447 0.000 {method 'append' of  
> 'list' objects}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 0.000 0.000 0.000 0.000 {method 'disable' of  
> '\_lsprof.Profiler' objects}  
> &nbsp;&nbsp;&nbsp;100000 0.279 0.000 0.279 0.000 {method 'items' of  
> 'dict' objects}  
> &nbsp;&nbsp;&nbsp;100000 0.509 0.000 0.509 0.000 {method 'split' of 'str'  
> objects}  
> &nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Antonio\_Cangiano](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@Antonio\_Cangiano](https://rubytalk.org/u/Antonio_Cangiano)\
**Post date:** [28 November 2007 11:10 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/5 "2007-11-28T11:10:05Z")

</div>

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

> **···**
>
> On Nov 28, 5:33 am, 庞旭晓 \<longxux...@hotmail.com\> wrote:
> 
> > what about python3.0? 5month is not a long time.

---

<div class="post-metadata">

**Author:** ![Just\_Another\_Victim1](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@Just\_Another\_Victim1](https://rubytalk.org/u/Just_Another_Victim1)\
**Post date:** [28 November 2007 12:00 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/6 "2007-11-28T12:00:09Z")

</div>

"hemant" \<gethemant@gmail.com\> wrote in message  
news:fb283d5e0711280259g5f40e5b0n6b97f5787c0bf414@mail.gmail.com...

> **···**
>
> > On Nov 28, 2007 3:55 PM, Antonio Cangiano \<acangiano@gmail.com\> wrote:
> > 
> > > 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!
> > > 
> > > [Holy Shmoly, Ruby 1.9 smokes Python away! | Programming Zen](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?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Indeed, as Python moves towards iterators over actual lists, it will  
> only get faster...

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [28 November 2007 11:58 UTC](https://rubytalk.org/t/ruby-1-9-might-just-be-faster-than-python/42569/7 "2007-11-28T11:58:44Z")

</div>

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...)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
