Created
September 26, 2015 15:36
-
-
Save sferik/26bec430d89d46271831 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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