From: "Joe Wölfel" Date: 2008-09-22T01:21:55+09:00 Subject: Re: for or each? It's hard to predict performance in advance. I think it's gotten harder as processors have become more complicated and there are more alternatives for running code. I'm just guessing here, but maybe blocks are so critical to ruby performance that 'each' has benefited from attempts to optimize the performance of blocks in general. -Joe On 21 sept. 08, at 11:44, Charles Oliver Nutter wrote: > Joe Wölfel wrote: >> You can try my test if you like. I haven't checked it carefully. >> But it does seem like 'each' is much faster under both ruby 1.86 >> and ruby 1.9. The code is below. > > Odd, now that I try it, each *is* faster than for. I'm going to > have to investigate. > > JRuby: > user system total real > for loop 0.334000 0.000000 0.334000 ( 0.334033) > each 0.236000 0.000000 0.236000 ( 0.235695) > > Ruby 1.8.6: > user system total real > for loop 1.050000 0.010000 1.060000 ( 1.079704) > each 0.950000 0.010000 0.960000 ( 0.982576) > > Ruby 1.9: > user system total real > for loop 0.910000 0.010000 0.920000 ( 0.933510) > each 0.420000 0.000000 0.420000 ( 0.431548) > > - Charlie > >