Created
July 6, 2016 06:23
-
-
Save weapp/0066ca6007fd8654fcb35f9d7dffd98a to your computer and use it in GitHub Desktop.
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
require 'securerandom' | |
require 'benchmark/ips' | |
hashs = 20.times.map do | |
20.times.map { [SecureRandom.hex(2), SecureRandom.hex(2)] }.to_h | |
end | |
Benchmark.ips do |x| | |
x.time = 5 | |
x.warmup = 2 | |
x.report("merge") { hashs.reduce(&:merge) } | |
x.report("merge!") { hashs.reduce({}, &:merge!) } | |
x.compare! | |
end | |
# Warming up -------------------------------------- | |
# merge 52.000 i/100ms | |
# merge! 896.000 i/100ms | |
# Calculating ------------------------------------- | |
# merge 629.419 (±24.8%) i/s - 2.860k in 5.040327s | |
# merge! 9.915k (±29.9%) i/s - 43.904k in 5.069974s | |
# Comparison: | |
# merge!: 9915.1 i/s | |
# merge: 629.4 i/s - 15.75x slower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment