为什么python的timeit使用'best of of 3'来衡量经过的时间?

zel*_*ell 11 python benchmarking timeit microbenchmark

我没有看到为什么python的timeit模块使用the来测量时间的原因best of 3.这是我的控制台的一个例子:

~ python -m timeit 'sum(range(10000))'
10000 loops, best of 3: 119 usec per loop
Run Code Online (Sandbox Code Playgroud)

直觉上,我会将整个时间放在一起然后除以循环次数.在所有循环中获得最佳3的直觉是什么?这似乎有点不公平.

Sim*_*ser 7

文档所述:

default_timer()测量可能会受到在同一台机器上运行的其他程序的影响,因此在需要精确计时时最好的做法是重复几次计时并使用最佳时间.-r选项对此有利; 在大多数情况下,默认的3次重复可能就足够了.