Created
November 26, 2017 01:00
-
-
Save garettarrowood/34be20405cfd1b2e618d02c4915d333b to your computer and use it in GitHub Desktop.
Hash#merge! vs hash assignment Benchmarks
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
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