Benchmark of loops

e$B!!$5$5$@$G$9!%e(B

e$B!!e(BVMware
e$B>e$G$9$,!$%k!<%W$K$D$$$F%Y%s%A%^!<%/$r<h$C$F$_$?$N$G$4Js9pe(B
e$B$G$9!%e(B

e$B!!$5$9$,$K!$%M%$%F%#%V$K<BAu$7$?e(B generator
e$B$OB.$$$J$!!$$G$b$d$C$Q$je(B
e$BIaDL$N%k!<%W$h$j$bA4A3CY$$$J$!!$$H$$$&46$8$G$9!%e(B

$ make benchmark-each MATZRUBY=which ruby ITEM=loop
./miniruby …/trunk/runruby.rb --extout=.ext –
…/trunk/benchmark/run.rb bm_loop --ruby=./ruby
–matzruby=/usr/bin/ruby --opts=-I…/trunk/lib
MatzRuby:
ruby 1.8.5 (2006-08-25) [i486-linux]
Ruby:
ruby 1.9.0 (2007-08-22 patchlevel 0) [i686-linux]


loop_generator:
max = 6000000

if defined? Fiber
gen = (1…max).each
else
require ‘generator’
gen = Generator.new((0…max))
end

if true
while gen.next?
gen.next
end
else
(0…max).each{|e|}
end

matz 419.819
ruby 30.508

loop_times:
30000000.times{|e|}

matz 49.387
ruby 6.977

loop_whileloop:
i = 0
while i<30000000 # benchmark loop 1
i+=1
end

matz 23.474
ruby 2.757

loop_whileloop2:
i=0
while i<6000000 # benchmark loop 2
i+=1
end


matz 4.936
ruby 0.539

– benchmark summary ---------------------------
loop_generator 419.819 30.508
loop_times 49.387 6.977
loop_whileloop 23.474 2.757
loop_whileloop2 4.936 0.539