Class: Perfer::ResultsFormatter

Inherits:
Object
  • Object
show all
Includes:
Formatter
Defined in:
lib/perfer/formatter/results_formatter.rb

Constant Summary

Constants included from Formatter

Formatter::TIME_UNITS

Instance Method Summary collapse

Methods included from Formatter

#float_scale, #format_duration, #format_duration_and_error, #format_error, #format_float, #format_ips, #format_n, #format_time, #max_length_of, #ruby_version, #short_ruby_description

Constructor Details

#initialize(results) ⇒ ResultsFormatter

Returns a new instance of ResultsFormatter.



5
6
7
8
# File 'lib/perfer/formatter/results_formatter.rb', line 5

def initialize(results)
  @results = Array(results)
  @max_job_length = max_length_of(@results) { |r| r[:job] }
end

Instance Method Details

#job_title(result) ⇒ Object



10
11
12
# File 'lib/perfer/formatter/results_formatter.rb', line 10

def job_title(result)
  result[:job].to_s.ljust(@max_job_length)
end

#max_input_size_lengthObject



14
15
16
# File 'lib/perfer/formatter/results_formatter.rb', line 14

def max_input_size_length
  @max_input_size_length ||= max_length_of(@results) { |r| r[:input_size] }
end

#report(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/perfer/formatter/results_formatter.rb', line 18

def report(options = {})
  measurements = options[:measurements]
  @results.each do |result|
    MeasurementsFormatter.new(result.data).report if measurements
    r = result
    stats = r.stats
    mean = stats.mean
    error = stats.maximum_absolute_deviation
    if r[:iterations]
      time_per_i, ips = mean/r[:iterations], r[:iterations]/mean
      error /= r[:iterations]
      puts "#{job_title(r)} #{format_duration_and_error time_per_i, error, '/i'} <=> #{format_ips ips} ips"
    else
      n = format_n(r[:input_size], max_input_size_length)
      puts "#{job_title(r)} #{n} in #{format_duration_and_error mean, error}"
    end
  end
end