class Benchmark::Memory::Measurement

Encapsulate the combined metrics of an action.

Attributes

memory[R]

@return [Metric] The memory allocation metric.

metrics[R]

@return [Array<Metric>] The metrics for the measurement.

objects[R]

@return [Metric] The object allocation metric.

strings[R]

@return [Metric] The string allocation metric.

Public Class Methods

from_result(result) click to toggle source

Create a Measurement from a MemoryProfiler::Results object.

@param result [MemoryProfiler::Results]

The results of a MemoryProfiler report.
# 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
new(memory:, objects:, strings:) click to toggle source

Instantiate a Measurement of memory usage.

@param memory [Metric] The memory usage of an action. @param objects [Metric] The object allocations of an action. @param strings [Metric] The string allocations of an action.

# File lib/benchmark/memory/measurement.rb, line 41
def initialize(memory:, objects:, strings:)
  @memory = memory
  @objects = objects
  @strings = strings
  @metrics = [@memory, @objects, @strings]
end

Public Instance Methods

<=>(other) click to toggle source

Compare two measurements for sorting purposes.

@param other [Measurement] The other measurement

@return [Integer]

# File lib/benchmark/memory/measurement.rb, line 68
def <=>(other)
  memory <=> other.memory
end
allocated_memory() click to toggle source

Total amount of allocated memory for the measurement.

@return [Integer]

# File lib/benchmark/memory/measurement.rb, line 75
def allocated_memory
  memory.allocated
end