Sha256: 8320a306a71a4a5a8a71a208584136ae58a080c60cdb10b740a2a5b6c56c207f

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

Bundler.require(:benchmarks)

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

  param :foo
  param :bar
  param :baz
end

class WithOneDefault
  extend Dry::Initializer

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

class WithTwoDefaults
  extend Dry::Initializer

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

class WithThreeDefaults
  extend Dry::Initializer

  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

10 entries across 10 versions & 1 rubygems

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