Created
January 10, 2020 16:25
-
-
Save dnesteryuk/ced55d30ccc73e704ef3c25ddc1180c5 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 'ostruct' | |
require 'benchmark/ips' | |
class User | |
attr_accessor :name, :email | |
def initialize(attrs) | |
attrs.each { |key, val| send("#{key}=", val) } | |
end | |
end | |
Benchmark.ips do |x| | |
x.report('class with accessors') { User.new(name: 'John', email: '[email protected]') } | |
x.report('OpenStruct') { OpenStruct.new(name: 'John', email: '[email protected]') } | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment