Skip to content

Instantly share code, notes, and snippets.

@sferik
Created September 26, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/26bec430d89d46271831 to your computer and use it in GitHub Desktop.
Save sferik/26bec430d89d46271831 to your computer and use it in GitHub Desktop.
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