Sha256: ebea26612a0b0be73c9cb55a9004949d48312015f0e057f599fe09e1bf533d8a

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
astruct-2.9.0 bench/add_more_vs_ostruct.rb