Today I ran the following script with Ruby 1.8 & Ruby 1.9 to compare their performances:
def bench
start = Time.now
1000000.times do
yield
end
puts Time.now - start
end
puts "Test 1: do things"
bench {
"yeho!12".next
rand(100)
i ||= 1
i = i + 1
}
puts "Test 2: \"stuff\""
bench {
"stuff"
}
puts "Test 3: 'stuff'"
bench {
'stuff'
}
puts "Test 4: :stuff"
bench {
:stuff
}
Ruby 1.9 performances are promising:
| Test | Ruby 1.8 (sec) | Ruby 1.9 (sec) | Perf Increase |
| Test 1: do things | 1.76 | 0.54 | 324.40% |
| Test 2: "stuff" | 0.76 | 0.21 | 364.53% |
| Test 3: 'stuff' | 0.80 | 0.21 | 388.91% |
| Test 4: :stuff | 0.70 | 0.13 | 525.98% |
So Ruby 1.9 is 3 to 5 times faster than Ruby 1.8 to run simple operations. I then checked with a small Rails app.
Once I got rubygem installed for Ruby 1.9, the gems I needed installed for Ruby 1.9, the plug-ins I use patched for Ruby 1.9, and my ruby code patched for Ruby 1.9, – yes, it was painful! – I fired: time spec spec
Ruby 1.8
$> time spec spec ............................................ Finished in 0.594813 seconds 44 examples, 0 failures spec spec 2.49s user 0.79s system 93% cpu 3.522 total
Ruby 1.9
$> time spec spec ............................................ Finished in 0.625589223 seconds 44 examples, 0 failures spec spec 8.74s user 0.32s system 93% cpu 9.648 total
Grrrr. Ruby 1.8 & 1.9 both pass the specs in ~0.60 second but Ruby 1.9 takes 8.74 seconds in total vs 2.49 seconds for Ruby 1.8. The same behavior occurs when running a Webrick server via script/server: Ruby 1.9 is 2 times slower than Ruby 1.8 to boot up the server and it handles the requests just as fast as Ruby 1.8.
Any Ruby guru to explain such deceiving results?
Entries (RSS)
Follow me on Twitter
LinkedIn profile
Photos
Videos
One Comment
I’m seeing similar results–I just ran benchmarks using 1.8.7 (REE) and 1.9.1, and 1.9.1 was over 50% *slower*. Running in production mode in both cases, using these ab settings:
ab -kc 10 -t 30 http://localhost:8080/foo
Not at all what I expected–I was hoping for this 2x improvement I keep reading about.
I’m hoping that Rails or Ruby or both need some kind of tuning or optimization for 1.9.1; if anyone has any ideas about that, I’d love to hear them.