为什么 python 的 timeit 使用 'best of 3' 来测量经过的时间?
Why does python's timeit use the 'best of 3' to measure the time elapsed?
我不明白为什么 python 的 timeit 模块使用 best of 3
测量时间。这是来自我的控制台的示例:
~ python -m timeit 'sum(range(10000))'
10000 loops, best of 3: 119 usec per loop
凭直觉,我会将整个时间放在一起,然后除以循环次数。在所有循环中选择最好的 3 个的直觉是什么?好像有点不公平。
default_timer() measurations can be affected by other programs running on the same machine, so the best thing to do when accurate timing is necessary is to repeat the timing a few times and use the best time. The -r option is good for this; the default of 3 repetitions is probably enough in most cases.
我不明白为什么 python 的 timeit 模块使用 best of 3
测量时间。这是来自我的控制台的示例:
~ python -m timeit 'sum(range(10000))'
10000 loops, best of 3: 119 usec per loop
凭直觉,我会将整个时间放在一起,然后除以循环次数。在所有循环中选择最好的 3 个的直觉是什么?好像有点不公平。
default_timer() measurations can be affected by other programs running on the same machine, so the best thing to do when accurate timing is necessary is to repeat the timing a few times and use the best time. The -r option is good for this; the default of 3 repetitions is probably enough in most cases.