Sha256: 17226179d155bb2f10a4d30714fade541fdc1d854010d99b57a408d134407b84

Contents?: true

Size: 944 Bytes

Versions: 9

Compression:

Stored size: 944 Bytes

Contents

Bundler.require(:benchmarks)

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

  param  :foo
  option :bar
end

class DefaultsTest
  extend Dry::Initializer::Mixin

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

class TypesTest
  extend Dry::Initializer::Mixin

  param  :foo, proc(&:to_s)
  option :bar, proc(&:to_s)
end

class DefaultsAndTypesTest
  extend Dry::Initializer::Mixin

  param  :foo, proc(&:to_s), default: proc { "FOO" }
  option :bar, proc(&:to_s), default: proc { "BAR" }
end

puts "Benchmark for various options"

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

  x.report("no opts") do
    NoOptsTest.new "foo", bar: "bar"
  end

  x.report("with defaults") do
    DefaultsTest.new
  end

  x.report("with types") do
    TypesTest.new "foo", bar: "bar"
  end

  x.report("with defaults and types") do
    DefaultsAndTypesTest.new
  end

  x.compare!
end

Version data entries

9 entries across 9 versions & 1 rubygems

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