Class: Benchmark::Memory::HeldResults::MetricSerializer

Inherits:
Serializer
  • Object
show all
Defined in:
lib/benchmark/memory/held_results/metric_serializer.rb

Overview

Serialize metrics for holding between runs.

Instance Attribute Summary

Attributes inherited from Serializer

#object

Instance Method Summary collapse

Methods inherited from Serializer

#initialize, load, #to_json

Constructor Details

This class inherits a constructor from Benchmark::Memory::HeldResults::Serializer

Instance Method Details

#load(hash) ⇒ Measurement::Metric

Convert a JSON hash into a Metric.

Parameters:

  • hash (Hash)

    A JSON document hash.

Returns:



15
16
17
18
19
20
21
22
# File 'lib/benchmark/memory/held_results/metric_serializer.rb', line 15

def load(hash)
  @object = Measurement::Metric.new(
    hash["type"],
    hash["allocated"],
    hash["retained"]
  )
  self
end

#to_hHash

Convert the metric to a Hash.

Returns:

  • (Hash)

    The metric as a Hash.



27
28
29
30
31
32
33
# File 'lib/benchmark/memory/held_results/metric_serializer.rb', line 27

def to_h
  {
    :allocated => object.allocated,
    :retained  => object.retained,
    :type      => object.type,
  }
end