Sha256: eeb4c63215933a94392f80843064680fcf0bf3ddabd187905385324a8de31d40

Contents?: true

Size: 829 Bytes

Versions: 8

Compression:

Stored size: 829 Bytes

Contents

Bundler.require(:benchmarks)

class PlainRubyTest
  attr_reader :foo, :bar

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

require "dry-initializer"
class DryTest
  extend Dry::Initializer::Mixin

  option :foo
  option :bar
end

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

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

puts "Benchmark for instantiation without 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("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

8 entries across 8 versions & 1 rubygems

Version Path
dry-initializer-1.4.1 benchmarks/without_options.rb
dry-initializer-1.4.0 benchmarks/without_options.rb
dry-initializer-1.3.0 benchmarks/without_options.rb
dry-initializer-1.2.0 benchmarks/without_options.rb
dry-initializer-1.1.3 benchmarks/without_options.rb
dry-initializer-1.1.2 benchmarks/without_options.rb
dry-initializer-1.1.1 benchmarks/without_options.rb
dry-initializer-1.1.0 benchmarks/without_options.rb