Sha256: 3200c65fb34b8deb91de7fb0e493ff454314c9871e1ccc93cdf8515357fa8919

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

Bundler.require(:benchmarks)

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

  option :foo, default: -> { "FOO" }
  option :bar, default: -> { "BAR" }
end

class DryTestUndefined
  extend Dry::Initializer

  option :foo, default: -> { "FOO" }
  option :bar, default: -> { "BAR" }
end

class PlainRubyTest
  attr_reader :foo, :bar

  def initialize(foo: "FOO", bar: "BAR")
    @foo = foo
    @bar = bar
  end
end

require "kwattr"
class KwattrTest
  kwattr foo: "FOO", bar: "BAR"
end

require "active_attr"
class ActiveAttrTest
  include ActiveAttr::AttributeDefaults

  attribute :foo, default: "FOO"
  attribute :bar, default: "BAR"
end

puts "Benchmark for instantiation with default values"

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

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

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

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

  x.report("kwattr") do
    KwattrTest.new
  end

  x.report("active_attr") do
    ActiveAttrTest.new
  end

  x.compare!
end

Version data entries

9 entries across 9 versions & 1 rubygems

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