[New-bugs-announce] [issue24015] timeit should start with 1 loop, not 10

Joachim Breitner report at bugs.python.org
Mon Apr 20 15:28:04 CEST 2015


New submission from Joachim Breitner:

The docs for the timeit command line interface specify

If -n is not given, a suitable number of loops is calculated by trying successive powers of 10 until the total time is at least 0.2 seconds.

This sounds as if it it first tries 1, then 10, then 100 etc. But the code starts with 10 iterations. So even if the tested code already takes long enough (e.g. because it is a suitable loop itself), timit will by default test 10 loops.

I propose to change that, and replace

        # determine number so that 0.2 <= total time < 2.0
        for i in range(1, 10):
            number = 10**i

with

        # determine number so that 0.2 <= total time < 2.0
        for i in range(0, 10):
            number = 10**i

in Lib/timeit.py.

----------
components: Library (Lib)
messages: 241643
nosy: nomeata
priority: normal
severity: normal
status: open
title: timeit should start with 1 loop, not 10
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24015>
_______________________________________


More information about the New-bugs-announce mailing list