Sha256: 578e1751b1b37e11c7cc1612746fab07ed85acc2b0d638acc03704d9654088f3

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

Bundler.require(:benchmarks)

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

  param  :foo
  option :bar
end

class DefaultsTest
  extend Dry::Initializer

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

class TypesTest
  extend Dry::Initializer

  param  :foo, type: String
  option :bar, type: String
end

class DefaultsAndTypesTest
  extend Dry::Initializer

  param  :foo, type: String, default: proc { "FOO" }
  option :bar, type: String, 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

1 entries across 1 versions & 1 rubygems

Version Path
dry-initializer-0.0.1 benchmarks/options.rb