Sha256: fe4bd9685a322bd5c0fda4d04c964389a8730c91000b202af8f53baf800f4c5e

Contents?: true

Size: 948 Bytes

Versions: 20

Compression:

Stored size: 948 Bytes

Contents

Bundler.require(:benchmarks)

class PlainRubyTest
  attr_reader :foo, :bar

  def initialize(foo: "FOO", bar: "BAR")
    @foo = foo
    @bar = bar
    fail TypeError unless String === @foo
    fail TypeError unless String === @bar
  end
end

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

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

require "virtus"
class VirtusTest
  include Virtus.model

  attribute :foo, String, default: "FOO"
  attribute :bar, String, default: "BAR"
end

puts "Benchmark for instantiation with type constraints and default values"

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

  x.report("plain Ruby") do
    PlainRubyTest.new
  end

  x.report("dry-initializer") do
    DryTest.new
  end

  x.report("virtus") do
    VirtusTest.new
  end

  x.compare!
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
dry-initializer-0.11.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.10.2 benchmarks/with_types_and_defaults.rb
dry-initializer-0.10.1 benchmarks/with_types_and_defaults.rb
dry-initializer-0.10.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.9.3 benchmarks/with_types_and_defaults.rb
dry-initializer-0.9.2 benchmarks/with_types_and_defaults.rb
dry-initializer-0.9.1 benchmarks/with_types_and_defaults.rb
dry-initializer-0.9.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.8.1 benchmarks/with_types_and_defaults.rb
dry-initializer-0.8.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.7.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.6.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.5.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.4.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.3.3 benchmarks/with_types_and_defaults.rb
dry-initializer-0.3.2 benchmarks/with_types_and_defaults.rb
dry-initializer-0.3.1 benchmarks/with_types_and_defaults.rb
dry-initializer-0.3.0 benchmarks/with_types_and_defaults.rb
dry-initializer-0.2.1 benchmarks/with_types_and_defaults.rb
dry-initializer-0.2.0 benchmarks/with_types_and_defaults.rb