Created
June 16, 2015 16:11
-
-
Save yorickpeterse/d2cc45fc7e9117bb8886 to your computer and use it in GitHub Desktop.
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/ips' | |
require 'ostruct' | |
struct = Struct.new(:name) | |
Benchmark.ips do |bench| | |
bench.report 'Struct' do | |
struct.new(:name => 'Alice') | |
end | |
bench.report 'Struct inline' do | |
Struct.new(:name).new(:name => 'Alice') | |
end | |
bench.report 'OpenStruct' do | |
OpenStruct.new(:name => 'Alice') | |
end | |
bench.compare! | |
end |
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
Calculating ------------------------------------- | |
Struct 69.264k i/100ms | |
Struct inline 8.916k i/100ms | |
OpenStruct 11.488k i/100ms | |
------------------------------------------------- | |
Struct 1.300M (± 3.2%) i/s - 6.511M | |
Struct inline 89.434k (±13.2%) i/s - 445.800k | |
OpenStruct 133.604k (± 6.1%) i/s - 666.304k | |
Comparison: | |
Struct: 1299835.3 i/s | |
OpenStruct: 133604.2 i/s - 9.73x slower | |
Struct inline: 89434.1 i/s - 14.53x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment