Created
June 6, 2014 09:06
-
-
Save y13i/03ee42352dc66457724f to your computer and use it in GitHub Desktop.
Rubyでのベンチマークのやり方忘れそうなのでメモ
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" | |
N = 10000000 | |
Benchmark.benchmark Benchmark::CAPTION, 20, nil, "total", "average" do |bm| | |
results = {} | |
candidates = { | |
"some_candidate" => ->(i){"do something".capitalize}, | |
"another_candidate" => ->(i){"do something".sub(/\A\w/) {|match| match.upcase}}, | |
} | |
candidates.each do |name, proc| | |
results[name] = bm.report name do | |
N.times &proc | |
end | |
end | |
[ | |
total = results.values.reduce(&:+), | |
total / results.size, | |
] | |
end |
Author
y13i
commented
Jun 6, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment