class ComplexityAssert::LinearComplexityModel

Generates a sample of execution timings to run a linear regression in order to predict another execution time

Public Instance Methods

analyze(timings) click to toggle source
# File lib/complexity_assert/linear_complexity_model.rb, line 5
def analyze(timings)
  linear_model = SimpleLinearRegression.new(*timings.transpose)
  @slope = linear_model.slope
  @y_intercept = linear_model.y_intercept
end
predict_run_time(input_data_size) click to toggle source
# File lib/complexity_assert/linear_complexity_model.rb, line 11
def predict_run_time(input_data_size)
  @y_intercept + @slope * input_data_size
end
to_s() click to toggle source
# File lib/complexity_assert/linear_complexity_model.rb, line 15
def to_s
  "O(n)"
end