Class: Benchmark::Memory::Report::Comparator
- Inherits:
-
Object
- Object
- Benchmark::Memory::Report::Comparator
- Defined in:
- lib/benchmark/memory/report/comparator.rb
Overview
Compares two Entry for the purposes of sorting and outputting a Comparison.
Constant Summary collapse
- METRICS =
i[memory objects strings].freeze
- VALUES =
i[allocated retained].freeze
Instance Attribute Summary collapse
-
#metric ⇒ Symbol
readonly
The metric to compare, one of
:memory,:objects, or:strings. -
#value ⇒ Symbol
readonly
The value to compare, one of
:allocatedor:retained.
Class Method Summary collapse
-
.from_spec(spec) ⇒ Comparator
Instantiates a Comparator from a spec given by Job#compare!.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks whether a Comparator equals another.
-
#initialize(metric: :memory, value: :allocated) ⇒ Comparator
constructor
Instantiate a new comparator.
-
#to_proc ⇒ Proc
Converts the Comparator to a Proc for passing to a block.
Constructor Details
#initialize(metric: :memory, value: :allocated) ⇒ Comparator
Instantiate a new comparator
32 33 34 35 36 37 38 |
# File 'lib/benchmark/memory/report/comparator.rb', line 32 def initialize(metric: :memory, value: :allocated) raise ArgumentError, "Invalid metric: #{metric.inspect}" unless METRICS.include? metric raise ArgumentError, "Invalid value: #{value.inspect}" unless VALUES.include? value @metric = metric @value = value end |
Instance Attribute Details
#metric ⇒ Symbol (readonly)
Returns The metric to compare, one of :memory, :objects, or :strings.
41 42 43 |
# File 'lib/benchmark/memory/report/comparator.rb', line 41 def metric @metric end |
#value ⇒ Symbol (readonly)
Returns The value to compare, one of :allocated or :retained.
44 45 46 |
# File 'lib/benchmark/memory/report/comparator.rb', line 44 def value @value end |
Class Method Details
.from_spec(spec) ⇒ Comparator
Instantiates a Benchmark::Memory::Report::Comparator from a spec given by Job#compare!
18 19 20 21 22 23 24 25 26 |
# File 'lib/benchmark/memory/report/comparator.rb', line 18 def self.from_spec(spec) raise ArgumentError, 'Only send a single metric and value, in the form memory: :allocated' if spec.length > 1 metric, value = *spec.first metric ||= :memory value ||= :allocated new(metric: metric, value: value) end |
Instance Method Details
#==(other) ⇒ Boolean
Checks whether a Benchmark::Memory::Report::Comparator equals another
51 52 53 |
# File 'lib/benchmark/memory/report/comparator.rb', line 51 def ==(other) metric == other.metric && value == other.value end |
#to_proc ⇒ Proc
Converts the Benchmark::Memory::Report::Comparator to a Proc for passing to a block
58 59 60 |
# File 'lib/benchmark/memory/report/comparator.rb', line 58 def to_proc proc { |entry| entry.measurement.public_send(metric).public_send(value) } end |