Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created May 27, 2013 11:54
Show Gist options
  • Save rummelonp/5656679 to your computer and use it in GitHub Desktop.
Save rummelonp/5656679 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'benchmark'
require 'hashie/mash'
require 'active_support/ordered_options'
TIMES = 100000
Benchmark.bm(30) do |x|
x.report('Hash') do
TIMES.times do
h = {}
h[:string], h[:symbol], h[:integer] = 'string', :symbol, 1
[h[:string], h[:symbol], h[:integer]]
end
end
x.report('Hashie::Mash') do
TIMES.times do
h = Hashie::Mash.new
h.string, h.symbol, h.integer = 'string', :symbol, 1
[h.string, h.symbol, h.integer]
end
end
x.report('ActiveSupport::OrderedHash') do
TIMES.times do
h = ActiveSupport::OrderedHash.new
h[:string], h[:symbol], h[:integer] = 'string', :symbol, 1
[h[:string], h[:symbol], h[:integer]]
end
end
x.report('ActiveSupport::OrderedOptions') do
TIMES.times do
h = ActiveSupport::OrderedOptions.new
h.string, h.symbol, h.integer = 'string', :symbol, 1
[h.string, h.symbol, h.integer]
end
end
end
@rummelonp
Copy link
Author

                                     user     system      total        real
Hash                             0.160000   0.000000   0.160000 (  0.162455)
Hashie::Mash                     2.550000   0.000000   2.550000 (  2.557630)
ActiveSupport::OrderedHash       0.180000   0.000000   0.180000 (  0.178252)
ActiveSupport::OrderedOptions    1.580000   0.000000   1.580000 (  1.580437)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment