Sha256: d7054eacba0abf49fdd11725716a52caed4cb313675aeeb3e66f2fe6318d8b17

Contents?: true

Size: 1.54 KB

Versions: 31

Compression:

Stored size: 1.54 KB

Contents

Bundler.require(:benchmarks)

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

  param :foo
  param :bar
  param :baz
end

class WithOneDefault
  extend Dry::Initializer::Mixin

  param :foo
  param :bar
  param :baz, default: proc { "BAZ" }
end

class WithTwoDefaults
  extend Dry::Initializer::Mixin

  param :foo
  param :bar, default: proc { "BAR" }
  param :baz, default: proc { "BAZ" }
end

class WithThreeDefaults
  extend Dry::Initializer::Mixin

  param :foo, default: proc { "FOO" }
  param :bar, default: proc { "BAR" }
  param :baz, default: proc { "BAZ" }
end

puts "Benchmark for various options"

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

  x.report("without defaults") do
    WithoutDefaults.new "FOO", "BAR", "BAZ"
  end

  x.report("with 0 of 1 default used") do
    WithOneDefault.new "FOO", "BAR", "BAZ"
  end

  x.report("with 1 of 1 default used") do
    WithOneDefault.new "FOO", "BAR"
  end

  x.report("with 0 of 2 defaults used") do
    WithTwoDefaults.new "FOO", "BAR", "BAZ"
  end

  x.report("with 1 of 2 defaults used") do
    WithTwoDefaults.new "FOO", "BAR"
  end

  x.report("with 2 of 2 defaults used") do
    WithTwoDefaults.new "FOO"
  end

  x.report("with 0 of 3 defaults used") do
    WithThreeDefaults.new "FOO", "BAR", "BAZ"
  end

  x.report("with 1 of 3 defaults used") do
    WithThreeDefaults.new "FOO", "BAR"
  end

  x.report("with 2 of 3 defaults used") do
    WithThreeDefaults.new "FOO"
  end

  x.report("with 3 of 3 defaults used") do
    WithThreeDefaults.new
  end

  x.compare!
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
dry-initializer-1.4.1 benchmarks/several_defaults.rb
dry-initializer-1.4.0 benchmarks/several_defaults.rb
dry-initializer-1.3.0 benchmarks/several_defaults.rb
dry-initializer-1.2.0 benchmarks/several_defaults.rb
dry-initializer-1.1.3 benchmarks/several_defaults.rb
dry-initializer-1.1.2 benchmarks/several_defaults.rb
dry-initializer-1.1.1 benchmarks/several_defaults.rb
dry-initializer-1.1.0 benchmarks/several_defaults.rb
dry-initializer-1.0.0 benchmarks/several_defaults.rb
dry-initializer-0.11.0 benchmarks/several_defaults.rb
dry-initializer-0.10.2 benchmarks/several_defaults.rb
dry-initializer-0.10.1 benchmarks/several_defaults.rb
dry-initializer-0.10.0 benchmarks/several_defaults.rb
dry-initializer-0.9.3 benchmarks/several_defaults.rb
dry-initializer-0.9.2 benchmarks/several_defaults.rb
dry-initializer-0.9.1 benchmarks/several_defaults.rb
dry-initializer-0.9.0 benchmarks/several_defaults.rb
dry-initializer-0.8.1 benchmarks/several_defaults.rb
dry-initializer-0.8.0 benchmarks/several_defaults.rb
dry-initializer-0.7.0 benchmarks/several_defaults.rb