class BenchmarkDriver::Output::Compare

def humanize(value, width = 10)

def humanize(value, width = 10)
  if BenchmarkDriver::Result::ERROR.equal?(value)
    return sprintf(" %*s", width, 'ERROR')
  elsif value == 0.0
    return sprintf(" %*.3f", width, 0.0)
  elsif value < 0
    raise ArgumentError.new("Negative value: #{value.inspect}")
  end
  scale = (Math.log10(value) / 3).to_i
  return sprintf("%*s", width, value.to_s) if scale < 0 # like 1.23e-04
  prefix = sprintf("%*.3f", width, (value.to_f / (1000 ** scale)))
  suffix =
    case scale
    when 1; 'k'
    when 2; 'M'
    when 3; 'G'
    when 4; 'T'
    when 5; 'Q'
    else # < 1000 or > 10^15, no scale or suffix
      return " #{prefix}"
    end
  "#{prefix}#{suffix}"
end