Message223185
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. |
|
Date |
User |
Action |
Args |
2014-07-16 09:06:24 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, georg.brandl, vstinner |
2014-07-16 09:06:24 | serhiy.storchaka | set | messageid: <1405501584.54.0.115556422233.issue21988@psf.upfronthosting.co.za> |
2014-07-16 09:06:24 | serhiy.storchaka | link | issue21988 messages |
2014-07-16 09:06:24 | serhiy.storchaka | create | |
|