Class: Benchmark::Memory::Measurement
- Inherits:
-
Object
- Object
- Benchmark::Memory::Measurement
- Extended by:
- Forwardable
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/benchmark/memory/measurement.rb,
lib/benchmark/memory/measurement/metric.rb
Overview
Encapsulate the combined metrics of an action.
Defined Under Namespace
Classes: Metric
Instance Attribute Summary collapse
-
#memory ⇒ Metric
readonly
The memory allocation metric.
-
#metrics ⇒ Array<Metric>
readonly
The metrics for the measurement.
-
#objects ⇒ Metric
readonly
The object allocation metric.
-
#strings ⇒ Metric
readonly
The string allocation metric.
Class Method Summary collapse
-
.from_result(result) ⇒ Object
Create a Measurement from a MemoryProfiler::Results object.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare two measurements for sorting purposes.
-
#allocated_memory ⇒ Integer
Total amount of allocated memory for the measurement.
-
#initialize(memory:, objects:, strings:) ⇒ Measurement
constructor
Instantiate a Measurement of memory usage.
Constructor Details
#initialize(memory:, objects:, strings:) ⇒ Measurement
Instantiate a Measurement of memory usage.
41 42 43 44 45 46 |
# File 'lib/benchmark/memory/measurement.rb', line 41 def initialize(memory:, objects:, strings:) @memory = memory @objects = objects @strings = strings @metrics = [@memory, @objects, @strings] end |
Instance Attribute Details
#memory ⇒ Metric (readonly)
Returns The memory allocation metric.
49 50 51 |
# File 'lib/benchmark/memory/measurement.rb', line 49 def memory @memory end |
#metrics ⇒ Array<Metric> (readonly)
Returns The metrics for the measurement.
52 53 54 |
# File 'lib/benchmark/memory/measurement.rb', line 52 def metrics @metrics end |
#objects ⇒ Metric (readonly)
Returns The object allocation metric.
55 56 57 |
# File 'lib/benchmark/memory/measurement.rb', line 55 def objects @objects end |
#strings ⇒ Metric (readonly)
Returns The string allocation metric.
58 59 60 |
# File 'lib/benchmark/memory/measurement.rb', line 58 def strings @strings end |
Class Method Details
.from_result(result) ⇒ Object
Create a Measurement from a MemoryProfiler::Results object.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/benchmark/memory/measurement.rb', line 16 def self.from_result(result) memory = Metric.new( :memsize, result.total_allocated_memsize, result.total_retained_memsize ) objects = Metric.new( :objects, result.total_allocated, result.total_retained ) strings = Metric.new( :strings, result.strings_allocated.size, result.strings_retained.size ) new(:memory => memory, :objects => objects, :strings => strings) end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare two measurements for sorting purposes.
68 69 70 |
# File 'lib/benchmark/memory/measurement.rb', line 68 def <=>(other) memory <=> other.memory end |
#allocated_memory ⇒ Integer
Total amount of allocated memory for the measurement.
75 76 77 |
# File 'lib/benchmark/memory/measurement.rb', line 75 def allocated_memory memory.allocated end |