Why Ruby 1.8.2 is faster?

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.

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?

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"

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