Sha256: 9022fb6841c0701513e96445e68d734f1cf6c64f7e96287fabf1d642da191e30

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 KB

Contents

Bundler.require(:benchmarks)

require "dry-initializer"
class DryTest
  extend Dry::Initializer[undefined: false]

  param :foo
  param :bar
end

class DryTestUndefined
  extend Dry::Initializer

  param :foo
  param :bar
end

class PlainRubyTest
  attr_reader :foo, :bar

  def initialize(foo, bar)
    @foo = foo
    @bar = bar
  end
end

StructTest = Struct.new(:foo, :bar)

require "concord"
class ConcordTest
  include Concord.new(:foo, :bar)
end

require "values"
ValueTest = Value.new(:foo, :bar)

require "value_struct"
ValueStructTest = ValueStruct.new(:foo, :bar)

require "attr_extras"
class AttrExtrasText
  attr_initialize :foo, :bar
  attr_reader :foo, :bar
end

puts "Benchmark for instantiation with plain params"

Benchmark.ips do |x|
  x.config time: 15, warmup: 10

  x.report("plain Ruby") do
    PlainRubyTest.new "FOO", "BAR"
  end

  x.report("Core Struct") do
    StructTest.new "FOO", "BAR"
  end

  x.report("values") do
    ValueTest.new "FOO", "BAR"
  end

  x.report("value_struct") do
    ValueStructTest.new "FOO", "BAR"
  end

  x.report("dry-initializer") do
    DryTest.new "FOO", "BAR"
  end

  x.report("dry-initializer (with UNDEFINED)") do
    DryTestUndefined.new "FOO", "BAR"
  end

  x.report("concord") do
    ConcordTest.new "FOO", "BAR"
  end

  x.report("attr_extras") do
    AttrExtrasText.new "FOO", "BAR"
  end

  x.compare!
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dry-initializer-3.0.2 benchmarks/plain_params.rb
dry-initializer-3.0.1 benchmarks/plain_params.rb
dry-initializer-3.0.0 benchmarks/plain_params.rb
dry-initializer-2.5.0 benchmarks/plain_params.rb
dry-initializer-2.4.0 benchmarks/plain_params.rb
dry-initializer-2.3.0 benchmarks/plain_params.rb
dry-initializer-2.2.0 benchmarks/plain_params.rb
dry-initializer-2.1.0 benchmarks/plain_params.rb
dry-initializer-2.0.0 benchmarks/plain_params.rb