Module: Benchmark::IPS::Helpers

Defined in:
lib/benchmark/ips.rb

Constant Summary collapse

SUFFIXES =
['', 'k', 'M', 'B', 'T', 'Q'].freeze

Class Method Summary collapse

Class Method Details

.scale(value) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/benchmark/ips.rb', line 87

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