slow iterators in ruby 1.9 on mac 17. Jun 2008
If you ever wondered why your Ruby programs are not faster but much slower with Ruby 1.9 you might be using each or times iterators on large collections.
10000000.times {}
In fact if you do a benchmark,
require 'benchmark'
n = 10000000
Benchmark.bm do |x|
x.report { n.times {} }
end
you get stunning results.
$ ruby bench.rb
user system total real
0.720000 0.000000 0.720000 ( 0.721872)
$ ruby1.9 bench.rb
user system total real
16.670000 9.110000 25.780000 ( 25.923977)
When increasing the number of iterations by powers of ten it looks like the computational complexity of the times iterator is O(n) in Ruby 1.9. According to Antonio Cangiano this behaviour is specific to Mac OS X and does not appear on Linux.
Kommentare (2)