Module: Benchmark::Memory::Helpers

Included in:
Job::IOOutput::ComparisonFormatter, Job::IOOutput::EntryFormatter, Job::IOOutput::MetricFormatter
Defined in:
lib/benchmark/memory/helpers.rb

Overview

Helper methods for formatting output.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scale(value) ⇒ String

Scale a value into human-understandable terms.

Parameters:

  • value (Integer, Float)

    The value to scale.

Returns:

  • (String)

    The scaled value.



29
30
31
32
33
# File 'lib/benchmark/memory/helpers.rb', line 29

def scale(value)
  value = HumanReadableUnit.new(value)

  format("%10.3f#{value.unit}", value.to_f / (1000**value.scale))
end

Instance Method Details

#rjust(label) ⇒ String

Right-justifies to a length of 20 or adds a line of padding when longer.

Parameters:

  • label (#to_s)

    The label to justify.

Returns:

  • (String)

    The justified label.



14
15
16
17
18
19
20
21
22
# File 'lib/benchmark/memory/helpers.rb', line 14

def rjust(label)
  label = label.to_s

  if label.size > 20
    "#{label}\n#{' ' * 20}"
  else
    label.rjust(20)
  end
end