Sha256: 6514ccbb5fa29a6cc71236bc2b0dbc1e3b49f27dd68a5152bde7bbaa3e204bc9
Contents?: true
Size: 883 Bytes
Versions: 2
Compression:
Stored size: 883 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" class DryTest extend Dry::Initializer::Mixin 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-initializer-0.1.1 | benchmarks/with_types_and_defaults.rb |
dry-initializer-0.1.0 | benchmarks/with_types_and_defaults.rb |