Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created October 15, 2012 17:33
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tenderlove/3893852 to your computer and use it in GitHub Desktop.
require 'benchmark'
5.times do |i|
i = 10 ** i
h = Hash[i.times.map { |z| [z, z] }]
puts "N KEYS: #{i}"
puts
Benchmark.bm do |x|
x.report('dup') { 1000.times { h.dup } }
x.report('Hash[]') { 1000.times { Hash[h] } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment