# Why Ruby 1.8.2 is faster?

**URL:** <https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109>\
**Category:** Ruby\
**Created:** [September 20, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109 "2007-09-20T17:52:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 20, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109/1 "2007-09-20T17:52:34Z")

</div>

I had Ruby 1.8.2 on the Mac so it was able to run a program with 10,000  
iterations per second.

and then I installed 1.8.6 with Locomotive and then the program will  
only run at about 6,500 iterations per second.

so i wonder why 1.8.2 is so much faster? obviously 1.8.6 has a lot more  
features added to it.

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 20, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109/2 "2007-09-20T21:24:29Z")

</div>

On Sep 20, 2007, at 08:52, SpringFlowers AutumnMoon wrote:

> I had Ruby 1.8.2 on the Mac so it was able to run a program with  
> 10,000  
> iterations per second.
> 
> and then I installed 1.8.6 with Locomotive and then the program will  
> only run at about 6,500 iterations per second.
> 
> so i wonder why 1.8.2 is so much faster? obviously 1.8.6 has a lot  
> more  
> features added to it.

What program?

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 21, 2007, 12:44am UTC](https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109/3 "2007-09-21T00:44:09Z")

</div>

Eric H. wrote:

> What program?

How about something just like:

on my Mac, the 1.8.2 runs about 46% faster than 1.8.6

* * *

n = 1\_000\_000

start\_time = Time.now

for i in 1…n  
t = (1…10).inject {|x, y| x + y }  
end

finish\_time = Time.now

p t

puts  
print "Ruby ", RUBY\_VERSION, " patch ", RUBY\_PATCHLEVEL, " on ",  
RUBY\_PLATFORM

puts  
print “It took #{finish\_time - start\_time} seconds to run.”  
print " #{(n / (finish\_time - start\_time)).to\_i} iterations per  
second.\n"

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 21, 2007, 1:18am UTC](https://www.ruby-forum.com/t/why-ruby-1-8-2-is-faster/115109/4 "2007-09-21T01:18:05Z")

</div>

On Sep 20, 2007, at 15:44, SpringFlowers AutumnMoon wrote:

> Eric H. wrote:
> 
> > What program?  
> > How about something just like:
> 
> on my Mac, the 1.8.2 runs about 46% faster than 1.8.6
> 
> […]
> 
> print "Ruby ", RUBY\_VERSION, " patch ", RUBY\_PATCHLEVEL, " on ",  
> RUBY\_PLATFORM

This program doesn’t run on ruby 1.8.2, there is no RUBY\_PATCHLEVEL.

$ /usr/bin/ruby -ve ‘RUBY\_PATCHLEVEL’  
ruby 1.8.2 (2004-12-25) [universal-darwin8.0]  
-e:1: warning: useless use of a constant in void context  
-e:1: uninitialized constant RUBY\_PATCHLEVEL (NameError)

I used this one, which seems to be the core of it:

for i in 1…1\_000\_000  
t = (1…10).inject {|x, y| x + y }  
end

And I got opposite results:

$ pbpaste | time ruby -v -  
ruby 1.8.6 (2007-06-30 patchlevel 5000) [i686-darwin8.10.1]  
12.37 real 12.29 user 0.01 sys  
$ pbpaste | time /usr/bin/ruby -v -  
ruby 1.8.2 (2004-12-25) [universal-darwin8.0]  
16.23 real 16.13 user 0.02 sys

1.8.6 is 24% faster in this test.

and for what its worth:

$ pbpaste | time ruby19 -v -  
ruby 1.9.0 (2007-09-15 patchlevel 0) [i686-darwin8.10.1]  
syck.so: warning: method redefined; discarding old value  
3.57 real 3.50 user 0.01 sys
