Last active
October 15, 2015 19:16
-
-
Save som-poddar/16fb871753695cc44134 to your computer and use it in GitHub Desktop.
merge vs merge!
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
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