Created
April 1, 2013 04:17
-
-
Save mwitek/5283222 to your computer and use it in GitHub Desktop.
Benchmark test for passing a method to another vs just using an array and each
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 'benchmark' | |
repetitions = 1000000 | |
def assert_method(string) | |
string.kind_of?(String) | |
end | |
def assert_form_with_fields(assertion) | |
send(assertion, "blue") | |
send(assertion, "green") | |
send(assertion, "orange") | |
send(assertion, "red") | |
end | |
Benchmark.bm(20) do |x| | |
x.report "Passing method to method" do | |
repetitions.times do | |
assert_form_with_fields("assert_method") | |
end | |
end | |
x.report "using each" do | |
repetitions.times do | |
colors = ["blue","green","orange","red"] | |
colors.each {|color| assert_method color } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment