Created
August 7, 2008 13:36
-
-
Save Mikoangelo/4401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
TESTS = 1_000_000 | |
array = [1,2,3] | |
Benchmark.bmbm do |results| | |
results.report " for" do | |
TESTS.times do | |
for a in array | |
"foo" | |
end | |
end | |
end | |
results.report "each" do | |
TESTS.times do | |
array.each do |a| | |
"foo" | |
end | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rehearsal ---------------------------------------- | |
for 2.490000 0.030000 2.520000 ( 2.947099) | |
each 2.630000 0.030000 2.660000 ( 3.169486) | |
------------------------------- total: 5.180000sec | |
user system total real | |
for 2.510000 0.030000 2.540000 ( 3.117419) | |
each 2.630000 0.040000 2.670000 ( 3.330009) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment