On 2005-02-27, Robert Klemme <bob.news / gmx.net> wrote: > > "Fear Dubh" <feardubh / spam.spam> schrieb im Newsbeitrag > news:cvslbj$9ns$1 / reader01.news.esat.net... >> Does each have a fatter frame then? >> Is "for ... in ... do ..." more efficient? > > I would believe not, but you can test this yourself (hint "ruby -r profile" > and module Benchmark). $ ruby -v ruby 1.8.2 (2004-12-25) [i386-linux] ruby -rbenchmark -e 'n=10**6; [ proc{ (0...n).each{|x| x} }, proc{ for x in 0...n; x ;end }, proc{ n.times{|x| x} } ].each {|pr| puts Benchmark.measure(&pr) }' 0.370000 0.000000 0.370000 ( 0.376541) 0.320000 0.000000 0.320000 ( 0.339880) 0.370000 0.000000 0.370000 ( 0.391311) So for is slightly faster. But see, do you wonder what happens if you execute the above three benchmarks in reverse order? Just replace the "each" (after the three-element array) with "reverse_each"... ;) Csaba