Skip to content

Instantly share code, notes, and snippets.

@garettarrowood
Created November 26, 2017 01:00
Show Gist options
  • Save garettarrowood/34be20405cfd1b2e618d02c4915d333b to your computer and use it in GitHub Desktop.
Save garettarrowood/34be20405cfd1b2e618d02c4915d333b to your computer and use it in GitHub Desktop.
Hash#merge! vs hash assignment Benchmarks
hash = {a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9, j:10}
Benchmark.measure { 10_000_000.times { hash.merge!(k:11) } }
=> @real=5.950756500009447, @utime=5.62, @total=5.94
Benchmark.measure { 10_000_000.times { hash[:k] = 11 } }
=> @real=0.6477032300026622, @utime=0.6499999999999995, @total=0.6499999999999995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment