Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
17 lines (13 sloc) 247 Bytes
require "benchmark/ips"
require "ostruct"
def fast
{ field_1: 1, field_2: 2 }
end
def slow
OpenStruct.new(field_1: 1, field_2: 2)
end
Benchmark.ips do |x|
x.report("Hash") { fast }
x.report("OpenStruct") { slow }
x.compare!
end
You can’t perform that action at this time.