From: "Bartosz DziewoƄski" Date: 2012-07-03T05:53:10+09:00 Subject: Re: ruby performance 2012/7/2 Dan Connelly : > Here's my contribution: > > Ruby: > i = 0 > 10_000_000.times { i += 1 } > puts i > > Perl: > for my $n ( 0 .. 1e7 - 1) { > $i ++ > } > print "$i\n" > > Result: > Ruby: 2.970 seconds > Perl: 0.682 seconds > > Wow... The problem is that with every iteration inside #times, Ruby yield the current "index" to the block - even if the block doesn't use this variable at all. And calling the block is no small operation... start here[1] (this is the #times method, as defined in C) and see how deep the rabbit hole goes. [1] http://rxr.whitequark.org/mri/source/numeric.c#3441 -- Matma Rex