class Benchmark::Inputs::Report

Attributes

label[R]

The label for the report.

@return [String]

ratio[R]

The ratio of the speed from the fastest report compared to the speed from this report. In other words, the “slower than fastest by” multiplier for this report. Will be nil if the absolute difference in speed between the two reports falls within the combined measurement error.

This value is set by {Benchmark::Inputs::Job#compare!}.

@return [Float, nil]

Public Class Methods

new(label, invocs_per_sample) click to toggle source

@!visibility private

# File lib/benchmark/inputs.rb, line 199
def initialize(label, invocs_per_sample)
  @label = label.to_s
  @invocs_per_sample = invocs_per_sample.to_f
  @ratio = nil

  @n = 0
  @mean = 0.0
  @m2 = 0.0
end

Public Instance Methods

add_sample(time_ns) click to toggle source

@!visibility private

# File lib/benchmark/inputs.rb, line 210
def add_sample(time_ns)
  sample_ips = @invocs_per_sample * NS_PER_S / time_ns

  # see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
  # or Knuth's TAOCP vol 2, 3rd edition, page 232
  @n += 1
  delta = sample_ips - @mean
  @mean += delta / @n
  @m2 += delta * (sample_ips - @mean)
  @stddev = nil
end
ips() click to toggle source

The estimated speed for the report, in invocations per second.

@return [Float]

# File lib/benchmark/inputs.rb, line 225
def ips
  @mean
end
overlap?(faster) click to toggle source

@!visibility private

# File lib/benchmark/inputs.rb, line 242
def overlap?(faster)
  (faster.ips - faster.stddev) <= (self.ips + self.stddev)
end
slower_than!(faster) click to toggle source

@!visibility private

# File lib/benchmark/inputs.rb, line 237
def slower_than!(faster)
  @ratio = overlap?(faster) ? nil : (faster.ips / self.ips)
end
stddev() click to toggle source

The standard deviation of the estimated speed for the report.

@return [Float]

# File lib/benchmark/inputs.rb, line 232
def stddev
  @stddev ||= @n < 2 ? 0.0 : Math.sqrt(@m2 / (@n - 1))
end