# module Benchmark::IPS::Helpers

### Constants

SUFFIXES

### Public Class Methods

humanize_duration(duration_ns) click to toggle source

    # File lib/benchmark/ips.rb, line 126
    def humanize_duration(duration_ns)
      if duration_ns < 1000
        "%.2f ns" % duration_ns
      elsif duration_ns < 1_000_000
        "%.2f μs" % (duration_ns / 1000)
      elsif duration_ns < 1_000_000_000
        "%.2f ms" % (duration_ns / 1_000_000)
      else
        "%.2f s" % (duration_ns / 1_000_000_000)
      end
    end

scale(value) click to toggle source

    # File lib/benchmark/ips.rb, line 116
    def scale(value)
      scale = (Math.log10(value) / 3).to_i
      scale = 0 if scale < 0 || scale >= SUFFIXES.size
      suffix = SUFFIXES[scale]
      scaled_value = value.to_f / (1000 ** scale)

      "%10.3f#{suffix}" % scaled_value
    end