Class: WBench::TimingHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/wbench/timing_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ TimingHash

Returns a new instance of TimingHash.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/wbench/timing_hash.rb', line 3

def initialize(hash)
  # Remove 0 values as they indicate events that didn't occur
  hash = hash.delete_if { |key, value| value == 0 }

  # Grab the start time and offset the values against it.
  start_time = hash.min_by(&:last).last
  hash = hash.map { |key, value| [key, value - start_time] }

  # Order the results by value, lowest to highest
  hash.sort_by(&:last).each { |key, value| self[key] = value }
end