How can timing observations estimate startup overhead and per-item cost?
Simple linear regression fits elapsed time as slope times item count plus an intercept by minimizing squared vertical residuals.
Python example and interpretation
Timings five, eight and eleven seconds at one, two and three items imply slope three and intercept two. The zero-item cost is an extrapolation worth testing directly.
from statistics import linear_regression
fit=linear_regression([1,2,3],[5,8,11])
[fit.slope,fit.intercept]Result [3.0, 2.0]
中文
如何从样本数与耗时估计启动开销及每项成本?
一元线性回归拟合耗时等于斜率乘样本数再加截距,普通最小二乘最小化纵向残差平方和。
Python 算例与适用条件
处理 1、2、3 项分别耗时 5、8、11 秒,斜率 3、截距 2。启动成本是对零项的外推,真实空请求需要另测。
from statistics import linear_regression
fit=linear_regression([1,2,3],[5,8,11])
[fit.slope,fit.intercept]结果 [3.0, 2.0]