Comparing Ruby 1.9.1 to Ruby 1.8.7 In The Real World
Early last year, I wrote a solution to the Minimum Enclosing Circle problem in Ruby. I figured this code was "real world" enough to compare performance of Ruby 1.8.7 to Ruby 1.9.1. There are a lot of numbers flying around claiming Ruby 1.9 is anywhere from 5 - 10 times faster than 1.8.7 and I have verified this on very small code samples.
The MEC solution is more real world. Here are some benchmark numbers from running the code under both 1.8.7 and 1.9.1.
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
$ ruby mec.rb benchmark
user system total real
points: 1 0.000000 0.010000 0.010000 ( 0.004344)
points: 10 0.130000 0.000000 0.130000 ( 0.157543)
points: 100 0.960000 0.060000 1.020000 ( 1.044081)
points: 1000 14.710000 1.460000 16.170000 ( 16.820545)
points: 10000 186.660000 14.360000 201.020000 (218.940879)
$ rvm 1.9.1
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
$ ruby mec.rb benchmark
user system total real
points: 1 0.000000 0.000000 0.000000 ( 0.003518)
points: 10 0.060000 0.000000 0.060000 ( 0.074752)
points: 100 0.590000 0.000000 0.590000 ( 0.589993)
points: 1000 7.820000 0.000000 7.820000 ( 7.922892)
points: 10000 106.140000 0.620000 106.760000 (113.783464)
As you can see, I get anywhere from 39% - 47% better performance. Call Ruby 1.9.1 twice as fast as Ruby 1.8.7 in a real world code base. I think this is what we can expect out of real world code bases when transitioning to 1.9.1
As a side note, I am using Ruby Version Manager to switch between my system installed Ruby (1.8.7) and 1.9.1. Kudos to Wayne Seguin, author of rvm. It is a beautiful package.