Created
August 30, 2010 16:52
-
-
Save metaskills/557671 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'bench_press' | |
extend BenchPress | |
author 'Ken Collins' | |
summary 'Iterate over rows of array data.' | |
reps 10_000 | |
ROWS = [ | |
[1, 'Test', 'Body copy', Time.now], | |
[2, 'Hello', 'World', Time.now], | |
[3, 'Speed', 'Is important', Time.now] | |
].freeze | |
measure "Array#each" do | |
ROWS.each do |a| | |
a.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "for" do | |
for r in ROWS | |
r.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "Array#each_index" do | |
ROWS.each_index do |i| | |
ROWS[i].each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "Array#each_with_index" do | |
ROWS.each_with_index do |r,i| | |
r.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "Array#reverse_each" do | |
ROWS.reverse_each do |r| | |
r.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "Array#map" do | |
ROWS.map do |r| | |
r.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "Array#collect" do | |
ROWS.collect do |r| | |
r.each_with_index { |v,i| v ; i } | |
end | |
end | |
measure "while" do | |
i = 0 | |
while i < ROWS.size | |
ROWS[i].each_with_index { |v,i| v ; i } | |
i += 1 | |
end | |
end | |
measure "Array#size.times" do | |
ROWS.size.times do |i| | |
ROWS[i].each_with_index { |v,i| v ; i } | |
end | |
end | |
=begin | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment