Created
August 25, 2012 08:04
-
-
Save krainboltgreene/3462357 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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
DATA2 = (10_000..20_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct new with data then load with more data" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.marshal_load DATA2.dup | |
end | |
x.report "AStruct new with data then load with more data" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.load DATA2.dup | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct new with data then load with more data 1 i/100ms | |
# AStruct new with data then load with more data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct new with data then load with more data 3.2 (±0.0%) i/s - 16 in 5.032341s | |
# AStruct new with data then load with more data 4.4 (±23.0%) i/s - 21 in 5.033214s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct new with data then delete" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.delete_field :item1 | |
end | |
x.report "AStruct new with data then delete" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.delete :item1 | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct new with data then delete 1 i/100ms | |
# AStruct new with data then delete 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct new with data then delete 8.9 (±11.3%) i/s - 44 in 5.014542s | |
# AStruct new with data then delete 10.2 (±29.5%) i/s - 48 in 5.014586s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct dump with data" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.marshal_dump | |
end | |
x.report "AStruct dump with data" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.dump | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct dump with data 1 i/100ms | |
# AStruct dump with data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct dump with data 9.0 (±22.2%) i/s - 44 in 5.055799s | |
# AStruct dump with data 10.2 (±29.4%) i/s - 48 in 5.073042s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct new with data then assign new data" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.example1 = "red" | |
op.example2 = "blue" | |
op.example3 = "green" | |
end | |
x.report "AStructt new with data then assign new data" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.example1 = "red" | |
ap.example2 = "blue" | |
ap.example3 = "green" | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct new with data then assign new data 1 i/100ms | |
# AStructt new with data then assign new data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct new with data then assign new data 8.5 (±11.8%) i/s - 42 in 5.078029s | |
# AStructt new with data then assign new data 9.4 (±32.0%) i/s - 43 in 5.005849s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct inspect with data" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.inspect | |
end | |
x.report "AStruct inspect with data" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.inspect | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct inspect with data 1 i/100ms | |
# AStruct inspect with data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct inspect with data 8.2 (±24.4%) i/s - 40 in 5.085258s | |
# AStruct inspect with data 9.1 (±21.9%) i/s - 45 in 5.063373s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct load with data" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new | |
op.marshal_load DATA.dup | |
end | |
x.report "AStruct load with data" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new | |
ap.load DATA.dup | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct load with data 1 i/100ms | |
# AStruct load with data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct load with data 10.1 (±19.9%) i/s - 49 in 5.017475s | |
# AStruct load with data 10.3 (±29.1%) i/s - 50 in 5.090294s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct new with data then 3 deep and inspect" do | |
class OProfile < OpenStruct; end | |
op = OProfile.new DATA.dup | |
op.op2 = OProfile.new DATA.dup | |
op.op2.op3 = OProfile.new DATA.dup | |
op.inspect | |
end | |
x.report "AStruct new with data then 3 deep and inspect" do | |
class AProfile < AltStruct; end | |
ap = AProfile.new DATA.dup | |
ap.ap2 = AProfile.new DATA.dup | |
ap.ap2.ap3 = AProfile.new DATA.dup | |
ap.inspect | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct new with data then 3 deep and inspect 1 i/100ms | |
# AStruct new with data then 3 deep and inspect 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct new with data then 3 deep and inspect 2.0 (±0.0%) i/s - 10 in 5.184739s | |
# AStruct new with data then 3 deep and inspect 3.1 (±31.9%) i/s - 15 in 5.029310s |
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 'astruct' | |
require 'ostruct' | |
DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge! | |
Benchmark.ips do |x| | |
x.report "OStruct new with data" do | |
class OProfile < OpenStruct; end | |
OProfile.new DATA.dup | |
end | |
x.report "AStruct new with data" do | |
class AProfile < AltStruct; end | |
AProfile.new DATA.dup | |
end | |
end | |
# Calculating ------------------------------------- | |
# OStruct new with data 1 i/100ms | |
# AStruct new with data 1 i/100ms | |
# ------------------------------------------------- | |
# OStruct new with data 8.6 (±23.2%) i/s - 42 in 5.041086s | |
# AStruct new with data 9.7 (±30.8%) i/s - 47 in 5.101214s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment