Skip to content

Instantly share code, notes, and snippets.

@schneems
Created August 21, 2014 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schneems/96c16647f43575604627 to your computer and use it in GitHub Desktop.
Save schneems/96c16647f43575604627 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
env = {"foo" => "bar", "bar" => "baz", "baz" => "boo", "PATH_INFO" => "foo"}
Benchmark.ips do |x|
x.report("set and reset") do
env["PATH_INFO"] = "zoo"
env
env["PATH_INFO"] = "foo"
end
x.report("merge") { env.merge("PATH_INFO" => "zoo") }
x.report("dup") { env.dup["PATH_INFO"] = "zoo"}
end
Calculating -------------------------------------
set and reset 72210 i/100ms
merge 32360 i/100ms
dup 40064 i/100ms
-------------------------------------------------
set and reset 1505441.3 (±10.3%) i/s - 7437630 in 5.001122s
merge 440993.4 (±13.2%) i/s - 2168120 in 5.020391s
dup 603567.4 (±7.9%) i/s - 3004800 in 5.011971s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment