Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created August 14, 2016 17:56
Show Gist options
  • Save flash-gordon/fc9ea08dfe40644a6c5c449dd4c12e39 to your computer and use it in GitHub Desktop.
Save flash-gordon/fc9ea08dfe40644a6c5c449dd4c12e39 to your computer and use it in GitHub Desktop.
Bundler.setup(:default, :benchmarks)
Bundler.require
require 'benchmark'
require 'benchmark/ips'
b = { b: :b }
Benchmark.ips do |x|
x.report('merge') { { a: :a }.merge(b) }
x.report('keywords') { { a: :a, **b } }
x.compare!
end
__END__
Warming up --------------------------------------
merge 51.889k i/100ms
keywords 100.272k i/100ms
Calculating -------------------------------------
merge 584.229k (± 8.7%) i/s - 2.906M in 5.010994s
keywords 1.686M (± 6.5%) i/s - 8.423M in 5.019280s
Comparison:
keywords: 1685535.9 i/s
merge: 584228.6 i/s - 2.89x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment