Module: Benchmark::IPS::Helpers

Defined in:
lib/project/ips.rb

Class Method Summary collapse

Class Method Details

.scale(value) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/project/ips.rb', line 76

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