lib/benchmark_driver/output/simple.rb in benchmark_driver-0.16.0 vs lib/benchmark_driver/output/simple.rb in benchmark_driver-0.16.1
- old
+ new
@@ -1,15 +1,20 @@
class BenchmarkDriver::Output::Simple
NAME_LENGTH = 10
+ OPTIONS = {
+ humanize: ['--output-humanize true|false', TrueClass, 'Humanize result numbers (default: true)'],
+ }
+
# @param [Array<BenchmarkDriver::Metric>] metrics
# @param [Array<BenchmarkDriver::Job>] jobs
# @param [Array<BenchmarkDriver::Context>] contexts
- def initialize(metrics:, jobs:, contexts:)
+ def initialize(metrics:, jobs:, contexts:, options:)
@metrics = metrics
@context_names = contexts.map(&:name)
@name_length = jobs.map(&:name).map(&:size).max
+ @humanize = options.fetch(:humanize, true)
end
def with_warmup(&block)
@with_benchmark = false
without_stdout_buffering do
@@ -76,9 +81,11 @@
ensure
$stdout.sync = sync
end
def humanize(value)
+ return value unless @humanize
+
if BenchmarkDriver::Result::ERROR.equal?(value)
return " %#{NAME_LENGTH}s" % 'ERROR'
elsif value == 0.0
return " %#{NAME_LENGTH}.3f" % 0.0
elsif value < 0