Add memory profiler

This commit is contained in:
Tim Riley 2022-10-09 09:04:21 +11:00
parent e4e3ad0f6a
commit a0c245dbef
No known key found for this signature in database
2 changed files with 51 additions and 0 deletions

View File

@ -11,6 +11,7 @@ gem "dry-core", github: "dry-rb/dry-core", branch: "main"
group :benchmarks do
gem "benchmark-ips"
gem "benchmark-memory"
gem "memory_profiler"
gem "hanami-utils"
end

View File

@ -0,0 +1,50 @@
# frozen_string_literal: true
require "dry/configurable"
require "memory_profiler"
RETAIN = [] # rubocop:disable Style/MutableConstant
def inherit_only(times)
klass = Class.new do
extend Dry::Configurable
setting :name
setting :array_setting, default: %w[jane alice jen]
setting :hash_setting, default: {"abcd" => "efgh"}
end
times.times do
subclass = Class.new(klass)
RETAIN << subclass
end
end
def inherit_and_configure(times)
klass = Class.new do
extend Dry::Configurable
setting :name
setting :array_setting, default: %w[jane alice jen]
setting :hash_setting, default: {"abcd" => "efgh"}
end
times.times do |i|
subclass = Class.new(klass) do
configure do |config|
config.name = "class #{i}"
end
end
RETAIN << subclass
end
end
times = Integer(ENV.fetch("TIMES", 1))
profile = ENV.fetch("PROFILE", "inherit_and_configure")
report = MemoryProfiler.report do
send(profile, times)
end
report.pretty_print