Sha256: efa57a89ea1c1da2687a0a1bfec5ebf00991b625e311c61f0a6be838936a35a1

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

require 'dry/struct'
require 'virtus'
require 'fast_attributes'
require 'attrio'
require 'ostruct'

require 'benchmark/ips'

class VirtusUser
  include Virtus.model

  attribute :name, String
  attribute :age, Integer
end

class FastUser
  extend FastAttributes

  define_attributes initialize: true, attributes: true do
    attribute :name, String
    attribute :age,  Integer
  end
end

class AttrioUser
  include Attrio

  define_attributes do
    attr :name, String
    attr :age, Integer
  end

  def initialize(attributes = {})
    self.attributes = attributes
  end

  def attributes=(attributes = {})
    attributes.each do |attr,value|
      self.send("#{attr}=", value) if self.respond_to?("#{attr}=")
    end
  end
end

class DryStructUser < Dry::Struct
  attributes(name: 'string', age: 'form.int')
end

puts DryStructUser.new(name: 'Jane', age: '21').inspect

Benchmark.ips do |x|
  x.report('virtus') { VirtusUser.new(name: 'Jane', age: '21') }
  x.report('fast_attributes') { FastUser.new(name: 'Jane', age: '21') }
  x.report('attrio') { AttrioUser.new(name: 'Jane', age: '21') }
  x.report('dry-struct') { DryStructUser.new(name: 'Jane', age: '21') }

  x.compare!
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dry-struct-0.7.0 benchmarks/basic.rb
dry-struct-0.6.0 benchmarks/basic.rb
dry-struct-0.5.1 benchmarks/basic.rb
dry-struct-0.5.0 benchmarks/basic.rb
dry-struct-0.4.0 benchmarks/basic.rb
dry-struct-0.3.1 benchmarks/basic.rb
dry-struct-0.3.0 benchmarks/basic.rb
dry-struct-0.2.1 benchmarks/basic.rb
dry-struct-0.2.0 benchmarks/basic.rb
dry-struct-0.1.1 benchmarks/basic.rb
dry-struct-0.1.0 benchmarks/basic.rb
dry-struct-0.0.1 benchmarks/basic.rb