Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created February 2, 2012 22:26
Show Gist options
  • Select an option

  • Save ryanlecompte/1726180 to your computer and use it in GitHub Desktop.

Select an option

Save ryanlecompte/1726180 to your computer and use it in GitHub Desktop.
big_hash = 10_000.times.with_object({}) { |i, hash| hash[i] = Array.new(i) }
Benchmark.bm do |x|
x.report("values.min") { big_hash.values.min }
x.report("each_value.min") { big_hash.each_value.min }
end
__END__
$ ruby speed.rb
user system total real
values.min 0.000000 0.000000 0.000000 ( 0.005023)
each_value.min 0.010000 0.000000 0.010000 ( 0.004439)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment