1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# frozen_string_literal: true
require 'benchmark/memory/report/comparison'
require 'benchmark/memory/report/entry'
module Benchmark
module Memory
# Hold the results of a set of benchmarks.
class Report
# Instantiate a report to hold entries of tasks and measurements.
#
# @return [Report]
def initialize
@entries = []
@comparator = Comparator.new
end
# @return [Comparator] The {Comparator} to use when creating the {Comparison}.
attr_accessor :comparator
# @return [Array<Entry>] The entries in the report.
attr_reader :entries
# Add an entry to the report.
#
# @param task [Job::Task] The task to report about.
# @param measurement [Measurement] The measurements from the task.
#
# @return [Entry] the newly created entry.
def add_entry(task, measurement)
entry = Entry.new(task.label, measurement)
entries.push(entry)
entry
end
# Return true if the report is comparable.
#
# @return [Boolean]
def comparable?
comparison.possible?
end
# Compare the entries within a report.
#
# @return [Comparison]
def comparison
@comparison ||= Comparison.new(entries, comparator)
end
end
end
end
|