Skip to content

Instantly share code, notes, and snippets.

@kelan
Created February 24, 2010 18:27
Show Gist options
  • Save kelan/313693 to your computer and use it in GitHub Desktop.
Save kelan/313693 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# To test is using `defaults.merge(options)` or `defaults.merge!(options)`
# is faster, I ran the following (manually replacing 'merge' with 'merge!'
# as appropriate):
10000000.times do
defaults = {:a => 1, :b => 2, :c => 3, :d => 4}
options = {:a => "another value", :d => true}
options = defaults.merge!(options)
end
puts "done"
# And the run-times (in seconds, as reported by TextMate's
# script runner) were:
#
# merge: 56.69, 57.15, 57.26 avg: 57.03 seconds
# merge!: 36.04, 36.18, 36.04 avg: 36.09 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment