class Benchmark::Memory::HeldResults
Collate results that should be held until the next run.
def add_result(entry)
-
(void)-
Parameters:
-
entry(Report::Entry) -- The entry to hold.
def add_result(entry) with_hold_file('a') do |file| file.write EntrySerializer.new(entry) file.write "\n" end end
def any?
-
(Boolean)-
def any? if @path.is_a?(String) File.exist?(@path) else @path.size.positive? end end
def cleanup
-
(void)-
def cleanup File.delete(@path) if @path.is_a?(String) && File.exist?(@path) end
def holding?
-
(Boolean)-
def holding? !!@path end
def include?(entry)
-
(Boolean)-
Parameters:
-
entry(#label) -- The entry to check.
def include?(entry) holding? && any? && results.key?(entry.label) end
def initialize(path = nil)
-
path(String, IO) -- The path to write held results to.
def initialize(path = nil) @path = path @results = {} end
def load
-
(void)-
def load return unless holding? && any? results = with_hold_file do |file| file.map { |line| EntrySerializer.load(line) } end @results = results.map { |result| [result.label, result.measurement] }.to_h end
def with_hold_file(access_mode = 'r', &block)
-
(void)-
Parameters:
-
_block(Proc) -- The block to execute on each line of the file. -
access_mode(String) -- The mode to use when opening the file.
def with_hold_file(access_mode = 'r', &block) return unless @path if @path.is_a?(String) File.open(@path, access_mode, &block) else yield @path end end