Sha256: c730b08ccb32fb75fec5f85fe567239c6d4d483061bd1bbadf195fc0d8005d6c

Contents?: true

Size: 499 Bytes

Versions: 15

Compression:

Stored size: 499 Bytes

Contents

module WBench
  class TimingHash < Hash
    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
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
wbench-1.1.1 lib/wbench/timing_hash.rb
wbench-1.1.0 lib/wbench/timing_hash.rb
wbench-1.0.0 lib/wbench/timing_hash.rb
wbench-0.4.0 lib/wbench/timing_hash.rb
wbench-0.3.7 lib/wbench/timing_hash.rb
wbench-0.3.6 lib/wbench/timing_hash.rb
wbench-0.3.5 lib/wbench/timing_hash.rb
wbench-0.3.4 lib/wbench/timing_hash.rb
wbench-0.3.3 lib/wbench/timing_hash.rb
wbench-0.3.2 lib/wbench/timing_hash.rb
wbench-0.3.1 lib/wbench/timing_hash.rb
wbench-0.3.0 lib/wbench/timing_hash.rb
wbench-0.2.3 lib/wbench/timing_hash.rb
wbench-0.2.2 lib/wbench/timing_hash.rb
wbench-0.2.1 lib/wbench/timing_hash.rb