Class: CollectionHandlerBenchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/xml_optimization_benchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(run_time: nil) ⇒ CollectionHandlerBenchmark

Returns a new instance of CollectionHandlerBenchmark.



134
135
136
# File 'lib/tasks/xml_optimization_benchmark.rb', line 134

def initialize(run_time: nil)
  @run_time = run_time || 10
end

Instance Method Details

#runObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/tasks/xml_optimization_benchmark.rb', line 138

def run
  puts "-" * 40
  puts "CollectionHandler Memoization Benchmark"
  puts "-" * 40

  bench_class = Class.new(Lutaml::Model::Serializable) do
    attribute :items, :string, collection: true
    attribute :single, :string
    attribute :custom_coll, :string, collection: SomeCollection
  end

  attr_defs = bench_class.attributes.values

  job = Benchmark::IPS::Job.new
  job.config(time: @run_time, warmup: 3)

  job.report("collection? (memoized)") do
    attr_defs.each(&:collection?)
  end

  job.report("singular? (memoized)") do
    attr_defs.each(&:singular?)
  end

  job.report("collection_class (memoized)") do
    attr_defs.each(&:collection_class)
  end

  job.run
  puts
end