Add benchmark for Config#to_h (#152)

This gives a good indication of overall config read performance
This commit is contained in:
Tim Riley 2022-10-12 20:57:08 +11:00 committed by GitHub
parent 861644230b
commit ddccb0e511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -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