Class: Benchmark::Memory::HumanReadableUnit
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Benchmark::Memory::HumanReadableUnit
- Defined in:
- lib/benchmark/memory/human_readable_unit.rb
Overview
Transforms raw numbers into a human-readable scale and suffix
Instance Method Summary collapse
-
#scale ⇒ Integer
The exponential scale of the value.
-
#unit ⇒ String
The single-character unit for the value.
Instance Method Details
#scale ⇒ Integer
Returns the exponential scale of the value.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/benchmark/memory/human_readable_unit.rb', line 10 def scale scale = Math.log10(__getobj__) scale = 0 if scale.infinite? scale = (scale / 3).to_i if scale <= 5 scale else 0 end end |
#unit ⇒ String
Returns the single-character unit for the value.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/benchmark/memory/human_readable_unit.rb', line 23 def unit case scale when 1 then 'k' when 2 then 'M' when 3 then 'B' when 4 then 'T' when 5 then 'Q' else ' ' end end |