classification
Title: timeit: use powers of 2 in autorange(), instead of powers of 10
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: haypo, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-10-18 16:13 by haypo, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
timeit_autorange_pow2.patch haypo, 2016-10-18 16:13 review
timeit_autorange_numbers.patch serhiy.storchaka, 2016-10-22 08:30 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (8)
msg278899 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-10-18 16:13
In the issue #28240, I changed the default repeat from 3 to 5 in timeit. Serhiy wrote (msg277157): "For now default timeit run takes from 0.8 to 8 sec. Adding yet 5 sec makes a user more angry."

I propose to use powers to 2, instead of powers of 10, in timeit autorange to reduce the total duration of the microbenchmark.

* Without the patch, the worst case: 4.0 * 6 = 24 seconds.
* With the patch, the worst case is: 0.4 * 6 = 2.4 seconds

* 6: autorange (1 iteration) + 5 repeatition
* autorange uses a minimum of 200 ms, so the worst case is 200 ms * 10 before, or 200 ms * 2 after
msg278905 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-18 16:25
"131072 loops" in a report looks not human friendly. I would prefer using a sequence of round numbers: 1, 2, 5, 10, 20, 50, 100, ...
msg278906 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-10-18 16:27
> "131072 loops" in a report looks not human friendly.

In my perf module, I use 2^n syntax for numbers larger than 1024. Syntax accepted in command line arguments.
msg278915 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-18 17:04
The perf module doesn't report the number of loops by default.
msg278916 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-10-18 17:07
> The perf module doesn't report the number of loops by default.

Right, it's hidden by default. I consider that it's not an useful information for end users.

If you want more details (see the number of inner and outer loops), use --verbose ("python3 -m perf timeit -v ...") or the stats commands ("python3 -m perf stats file.json").
msg279187 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-22 08:30
Following patch takes numbers from the sequence 1, 2, 5, 10, 20, 50, ... It also updates the documentation and tests.
msg279245 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-10-23 09:26
timeit_autorange_numbers.patch: LGTM.
msg279254 - (view) Author: Roundup Robot (python-dev) Date: 2016-10-23 12:18
New changeset 8e6cc952adc6 by Serhiy Storchaka in branch 'default':
Issue #28469: timeit now uses the sequence 1, 2, 5, 10, 20, 50,... instead
https://hg.python.org/cpython/rev/8e6cc952adc6
History
Date User Action Args
2017-03-31 16:36:15dstufftsetpull_requests: + pull_request902
2016-10-23 12:19:09serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-10-23 12:18:00python-devsetnosy: + python-dev
messages: + msg279254
2016-10-23 09:26:22hayposetmessages: + msg279245
2016-10-22 08:30:57serhiy.storchakasetfiles: + timeit_autorange_numbers.patch

messages: + msg279187
components: + Library (Lib)
stage: patch review
2016-10-18 17:07:42hayposetmessages: + msg278916
2016-10-18 17:04:07serhiy.storchakasetmessages: + msg278915
2016-10-18 16:27:02hayposetmessages: + msg278906
2016-10-18 16:25:50serhiy.storchakasetmessages: + msg278905
2016-10-18 16:13:11haypocreate