Sha256: b4c41e5ee52a52b89e4ac301b0294fdfe1586dfe63a3a29c586d83fbbb52d12c

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

Bundler.require(:benchmarks)

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

  option :foo
  option :bar
end

class DryTestUndefined
  extend Dry::Initializer

  option :foo
  option :bar
end

class PlainRubyTest
  attr_reader :foo, :bar

  def initialize(options = {})
    @foo = options[:foo]
    @bar = options[:bar]
  end
end

require 'anima'
class AnimaTest
  include Anima.new(:foo, :bar)
end

require 'kwattr'
class KwattrTest
  kwattr :foo, :bar
end

puts 'Benchmark for instantiation with plain options'

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

  x.report('plain Ruby') do
    PlainRubyTest.new foo: 'FOO', bar: 'BAR'
  end

  x.report('dry-initializer') do
    DryTest.new foo: 'FOO', bar: 'BAR'
  end

  x.report('dry-initializer (with UNDEFINED)') do
    DryTestUndefined.new foo: 'FOO', bar: 'BAR'
  end

  x.report('anima') do
    AnimaTest.new foo: 'FOO', bar: 'BAR'
  end

  x.report('kwattr') do
    KwattrTest.new foo: 'FOO', bar: 'BAR'
  end

  x.compare!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-initializer-3.0.3 benchmarks/plain_options.rb