Skip to content

Instantly share code, notes, and snippets.

@jonatas
Created April 30, 2015 17:46
Show Gist options
  • Select an option

  • Save jonatas/6eaa699d08b507b7b7a7 to your computer and use it in GitHub Desktop.

Select an option

Save jonatas/6eaa699d08b507b7b7a7 to your computer and use it in GitHub Desktop.
benchmark compare
require "benchmark"
def compare hash, options={}
options[:times] ||= 10
Benchmark.bm(5) do |x|
hash.each do |action, execute|
x.report(action) {
options[:times].times { execute.() }
}
end
end
end
require "compare"
compare({
"YAML" => -> { YAML.load_file "config/database.yml" },
"Psych" => -> {Psych.load_file "config/database.yml"} }, { :times => 100_000 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment