Last active
January 29, 2016 10:00
-
-
Save jordifebrer/0b3c10ec6756095405b5 to your computer and use it in GitHub Desktop.
Struct vs OpenStruct vs Hash benchmark
This file contains 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' | |
require 'ostruct' | |
Benchmark.bm 10 do |bench| | |
bench.report "Hash: " do | |
10_000_000.times do { name: "John Doe", age: 32 } end | |
end | |
bench.report "Struct: " do | |
Person = Struct.new(:name, :age) | |
10_000_000.times do Person.new("John Doe", 32) end | |
end | |
bench.report "OpenStruct: " do | |
10_000_000.times do OpenStruct.new(name: "John Doe", age: 32) end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment