Skip to content

Instantly share code, notes, and snippets.

@som-poddar
Last active October 15, 2015 19:16
Show Gist options
  • Save som-poddar/16fb871753695cc44134 to your computer and use it in GitHub Desktop.
Save som-poddar/16fb871753695cc44134 to your computer and use it in GitHub Desktop.
merge vs merge!
main_hash = {}
K = 10000
start_time = Time.now
(1..K).each do |number|
main_hash = main_hash.merge({number => number})
end
puts "with 'merge'"
puts "Time elapsed #{Time.now - start_time} seconds"
puts "Main hash key count: #{main_hash.keys.count}"
main_hash2 = {}
start_time = Time.now
(1..K).each do |number|
main_hash2.merge!({number => number})
end
puts "with 'merge!'"
puts "Time elapsed #{Time.now - start_time} seconds"
puts "Main hash key count: #{main_hash2.keys.count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment