Skip to content

Instantly share code, notes, and snippets.

@manveru
Created November 1, 2010 12:55
Show Gist options
  • Save manveru/658119 to your computer and use it in GitHub Desktop.
Save manveru/658119 to your computer and use it in GitHub Desktop.
require 'ostruct'
require 'benchmark'
N = 200_000
string = "Hello, Kitty"
o = OpenStruct.new(hello: string)
S = Struct.new(:hello)
s = S.new(string)
Benchmark.bmbm(20) do |b|
b.report("create OS"){ N.times{ OpenStruct.new }}
b.report("write OS"){ N.times{ OpenStruct.new.hello = string }}
b.report("read OS"){ N.times{ o.hello }}
b.report("create S"){ N.times{ S.new }}
b.report("write S"){ N.times{ S.new.hello = string }}
b.report("read S"){ N.times{ s.hello }}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment