Class: Benchmark::Memory::HeldResults
- Inherits:
-
Object
- Object
- Benchmark::Memory::HeldResults
- Extended by:
- Forwardable
- Defined in:
- lib/benchmark/memory/held_results.rb,
lib/benchmark/memory/held_results/serializer.rb,
lib/benchmark/memory/held_results/entry_serializer.rb,
lib/benchmark/memory/held_results/metric_serializer.rb,
lib/benchmark/memory/held_results/measurement_serializer.rb
Overview
Collate results that should be held until the next run.
Defined Under Namespace
Classes: EntrySerializer, MeasurementSerializer, MetricSerializer, Serializer
Instance Attribute Summary collapse
-
#path ⇒ String, IO
The path to write held results to.
-
#results ⇒ Hash{String => Measurement}
readonly
Held results from previous runs.
Instance Method Summary collapse
-
#add_result(entry) ⇒ void
Add a result to the held results.
-
#any? ⇒ Boolean
Check whether any results have been stored.
-
#cleanup ⇒ void
Clean up the results after all results have been collated.
-
#holding? ⇒ Boolean
Check whether to hold results.
-
#include?(entry) ⇒ Boolean
Check whether an entry has been added to the results.
-
#initialize(path = nil) ⇒ HeldResults
constructor
Instantiate a new set of held results on a path.
-
#load ⇒ void
Load results from the serialized output.
Constructor Details
#initialize(path = nil) ⇒ HeldResults
Instantiate a new set of held results on a path.
13 14 15 16 |
# File 'lib/benchmark/memory/held_results.rb', line 13 def initialize(path = nil) @path = path @results = {} end |
Instance Attribute Details
#path ⇒ String, IO
Returns The path to write held results to.
19 20 21 |
# File 'lib/benchmark/memory/held_results.rb', line 19 def path @path end |
#results ⇒ Hash{String => Measurement} (readonly)
Returns Held results from previous runs.
22 23 24 |
# File 'lib/benchmark/memory/held_results.rb', line 22 def results @results end |
Instance Method Details
#add_result(entry) ⇒ void
This method returns an undefined value.
Add a result to the held results.
32 33 34 35 36 37 |
# File 'lib/benchmark/memory/held_results.rb', line 32 def add_result(entry) with_hold_file("a") do |file| file.write EntrySerializer.new(entry) file.write "\n" end end |
#any? ⇒ Boolean
Check whether any results have been stored.
42 43 44 45 46 47 48 |
# File 'lib/benchmark/memory/held_results.rb', line 42 def any? if @path.is_a?(String) File.exist?(@path) else @path.size > 0 # rubocop:disable Style/ZeroLengthPredicate end end |
#cleanup ⇒ void
This method returns an undefined value.
Clean up the results after all results have been collated.
53 54 55 56 57 |
# File 'lib/benchmark/memory/held_results.rb', line 53 def cleanup if @path.is_a?(String) && File.exist?(@path) File.delete(@path) end end |
#holding? ⇒ Boolean
Check whether to hold results.
62 63 64 |
# File 'lib/benchmark/memory/held_results.rb', line 62 def holding? !!@path end |
#include?(entry) ⇒ Boolean
Check whether an entry has been added to the results.
71 72 73 |
# File 'lib/benchmark/memory/held_results.rb', line 71 def include?(entry) holding? && any? && results.key?(entry.label) end |
#load ⇒ void
This method returns an undefined value.
Load results from the serialized output.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/benchmark/memory/held_results.rb', line 78 def load return unless holding? && any? results = with_hold_file do |file| file.map { |line| EntrySerializer.load(line) } end @results = Hash[results.map do |result| [result.label, result.measurement] end] end |