Skip to content

Instantly share code, notes, and snippets.

@chendo
Created May 28, 2013 06:55
Show Gist options
  • Save chendo/5660925 to your computer and use it in GitHub Desktop.
Save chendo/5660925 to your computer and use it in GitHub Desktop.
Benchmarking Hashie::Mash
# Benchmark results on 1.9.3p392, OS X, iMac i7 3.4Ghz
# Rehearsal --------------------------------------------------------
# Hash hit 0.020000 0.000000 0.020000 ( 0.024836)
# Mash hit via method 0.330000 0.010000 0.340000 ( 0.327954)
# Mash hit via [] 0.140000 0.000000 0.140000 ( 0.137176)
# Hash miss 0.020000 0.000000 0.020000 ( 0.025503)
# Mash miss via method 0.730000 0.000000 0.730000 ( 0.730849)
# Mash miss via [] 0.140000 0.000000 0.140000 ( 0.136285)
# ----------------------------------------------- total: 1.390000sec
# user system total real
# Hash hit 0.030000 0.000000 0.030000 ( 0.022808)
# Mash hit via method 0.310000 0.000000 0.310000 ( 0.309510)
# Mash hit via [] 0.140000 0.000000 0.140000 ( 0.132961)
# Hash miss 0.020000 0.000000 0.020000 ( 0.024958)
# Mash miss via method 0.720000 0.000000 0.720000 ( 0.723548)
# Mash miss via [] 0.140000 0.000000 0.140000 ( 0.131169)
require 'rubygems'
require 'hashie/mash'
require 'benchmark'
N = 100000
hash = {:foo => 'bar'}
mash = Hashie::Mash.new(hash)
Benchmark.bmbm do |x|
x.report("Hash hit") do
N.times do
hash[:foo]
end
end
x.report("Mash hit via method") do
N.times do
mash.foo
end
end
x.report("Mash hit via []") do
N.times do
mash[:foo]
end
end
x.report("Hash miss") do
N.times do
hash[:miss]
end
end
x.report("Mash miss via method") do
N.times do
mash.miss
end
end
x.report("Mash miss via []") do
N.times do
mash[:miss]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment