Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'benchmark/ips'
require 'ostruct'
N = 100
ATTRS = (:aa..:zz).take(N)
HASH = Hash[ATTRS.map { |x| [x, x] }]
CStruct = Struct.new(*ATTRS)
def struct
CStruct.new(*ATTRS)
end
def ostruct
OpenStruct.new(HASH)
end
Benchmark.ips do |x|
x.report('struct') { struct }
x.report('ostruct') { ostruct }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.