[issue32039] timeit documentation should describe caveats

Serhiy Storchaka report at bugs.python.org
Wed Nov 15 17:00:16 EST 2017


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

+1 to all said by Raymond. But this is rather the matter of a special article or blog post than a note in the documentation.

Other example of caching is regular expressions.

Mistakes:

python3 -m timeit -s "it = iter(range(1000000000))" "next(it)"

python3 -m timeit -s "a = []" "a.append(1)"

I remember one non-obvious trap in which I got caught. The performance of the iteration of a dict was influenced by the fact that in new dicts the order of iteration coincided with the order of creating keys, which were allocated sequentially in memory. Thus refcounts were touched in adjacent objects. This usually is not happen in real programs.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32039>
_______________________________________


More information about the Python-bugs-list mailing list