>>>>> "H" == Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes:

H> for i in (1..count)
H>     ...
H> end

H> Were about 12.??? seconds whereas 
H> (1..count).each {...}
H> were about 14.??? seconds (for counts of 500000)

 Well, I've tried 'loop_test(1200000)' and  'loop_test_iter(1200000)'and
I've not seen any *significative* difference.

pigeon% b.rb
loop_test_iter 1200000 elapsed: 9.936672
loop_test 1200000 elapsed: 9.936269
loop_test_iter 1200000 elapsed: 9.935942
pigeon% 

 and when you read in the source of this test

   # the "for" iterator has slightly slower performance:

 then you think that it's just a benchmark, and it's better to forget it. 

H> I expected the case where the Range did all the looping to be faster.
H> I thought that as iterators are good style in Ruby that they'd be fast.

 They do it in the same way

     for i in 1 .. count
     end

   1) evaluate '1..count' ==> the result is a Range
   2) call #each on the result

 this is what do

   (1..count).each {}

 the difference is only on dynamic/local variable.


Guy Decoux