Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created March 31, 2009 15:44
Show Gist options
  • Save fixlr/88237 to your computer and use it in GitHub Desktop.
Save fixlr/88237 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 100000
Benchmark.bm do |x|
x.report('copy') { n.times do ; h = {}; h = h.merge({1 => 2}); end }
x.report('no copy') { n.times do ; h = {}; h.merge!({1 => 2}); end }
end
# user system total real
# copy 0.460000 0.180000 0.640000 ( 0.640692)
# no copy 0.340000 0.120000 0.460000 ( 0.463339)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment