New submission from Serhiy Storchaka:

Currently timeit has significant iterating overhead when tests fast statements. 
Such overhead makes hard to measure effects of microoptimizations. To decrease 
overhead and get more precise results we should repeat tested statement many 
times:

$ ./python -m timeit -s "x=10"  "x+x"
1000000 loops, best of 3: 0.2 usec per loop
$ ./python -m timeit -s "x=10"  "x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; 
x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x; x+x"
100000 loops, best of 3: 14.6 usec per loop

Proposed patch makes it automatically for user. It unrolls and vectorize the 
loop, and decreases iterating overhead 1000 times:

$ ./python -m timeit -s "x=10"  "x+x"
10000000 loops, best of 3: 0.141 usec per loop

An user gets precision value without explicit cumbersome repeating.

----------
components: Library (Lib)
files: timeit_unroll_loops.patch
keywords: patch
messages: 223185
nosy: georg.brandl, haypo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Decrease iterating overhead it timeit
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file35966/timeit_unroll_loops.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21988>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to