Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created February 18, 2015 15:24
Show Gist options
  • Save tiegz/c697f09d645a4e609958 to your computer and use it in GitHub Desktop.
Save tiegz/c697f09d645a4e609958 to your computer and use it in GitHub Desktop.
Hash#dup/clone benches
require 'benchmark'
GC.disable
x = {:a => 1}
ms1 = 1000 * Benchmark.realtime { 1_000_000.times { x.dup } }
ms2 = 1000 * Benchmark.realtime { 1_000_000.times { x.clone } }
puts [
"#{RUBY_ENGINE rescue 'ruby'} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}...".ljust(30),
ms1.to_i.to_s.rjust(10) + "ms",
ms2.to_i.to_s.rjust(10) + "ms"
].join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment