Module: Benchmark::IPS::Helpers

Defined in:
lib/benchmark/ips.rb

Class Method Summary collapse

Class Method Details

.scale(value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/benchmark/ips.rb', line 74

def scale(value)
  scale = (Math.log10(value) / 3).to_i
  suffix = case scale
  when 1; 'k'
  when 2; 'M'
  when 3; 'B'
  when 4; 'T'
  when 5; 'Q'
  else
    # < 1000 or > 10^15, no scale or suffix
    scale = 0
    ' '
  end
  "%10.3f#{suffix}" % (value.to_f / (1000 ** scale))
end