Method: MiniTest::Unit::TestCase#assert_performance_constant

Defined in:
lib/minitest/benchmark.rb

#assert_performance_constant(threshold = 0.99, &work) ⇒ Object

Runs the given work and asserts that the times gathered fit to match a constant rate (eg, linear slope == 0) within a given error threshold.

Fit is calculated by #fit_constant.

Ranges are specified by ::bench_range.

Eg:

def bench_algorithm
  assert_performance_constant 0.9999 do |x|
    @obj.algorithm
  end
end

123
124
125
126
127
128
129
130
131
# File 'lib/minitest/benchmark.rb', line 123

def assert_performance_constant threshold = 0.99, &work
  validation = proc do |range, times|
    a, b, rr = fit_linear range, times
    assert_in_delta 0, b, 1 - threshold
    [a, b, rr]
  end

  assert_performance validation, &work
end