Skip to content

Instantly share code, notes, and snippets.

@kke
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save kke/4e2220c653555318960d to your computer and use it in GitHub Desktop.

Select an option

Save kke/4e2220c653555318960d to your computer and use it in GitHub Desktop.
Benchmark.bm do |x|
hash = {:foo => "foo"}
class Item
def initialize
@foo = "foo"
end
def foo
@foo
end
end
item = Item.new
x.report("hash") { 1_000_000.times { hash[:foo] } }
x.report("item") { 1_000_000.times { item.foo } }
end
user system total real
hash 0.200000 0.000000 0.200000 ( 0.200694)
item 0.230000 0.000000 0.230000 ( 0.225771)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment