Add benchmark for Config#to_h (#152)
This gives a good indication of overall config read performance
This commit is contained in:
parent
861644230b
commit
ddccb0e511
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "bundler/setup"
|
||||
|
||||
require "benchmark/ips"
|
||||
require "dry/configurable"
|
||||
|
||||
class Base
|
||||
extend Dry::Configurable
|
||||
|
||||
setting :foo
|
||||
setting :bar
|
||||
setting :baz, default: "baz"
|
||||
setting :qux, default: "qux", constructor: :upcase.to_proc
|
||||
|
||||
config.bar = "bar"
|
||||
end
|
||||
|
||||
class Sub1 < Base
|
||||
setting :quux
|
||||
end
|
||||
|
||||
class Sub2 < Sub1
|
||||
end
|
||||
|
||||
def name(str)
|
||||
[ENV["BENCHMARK_NAME"], str].compact.join("/")
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.warmup = 1
|
||||
x.time = 3
|
||||
|
||||
x.report(name("base")) do
|
||||
Base.config.to_h
|
||||
end
|
||||
|
||||
x.report(name("sub")) do
|
||||
Sub2.config.to_h
|
||||
end
|
||||
|
||||
x.save! ENV["SAVE_FILE"] if ENV["SAVE_FILE"]
|
||||
x.compare!
|
||||
end
|
Loading…
Reference in New Issue