-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30080: Add the --duplicate option for CLI of timeit. #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Doc/library/timeit.rst
Outdated
| @@ -227,6 +227,12 @@ Where the following options are understood: | |||
|
|
|||
| .. versionadded:: 3.5 | |||
|
|
|||
| .. cmdoption:: --duplicate=D | |||
|
|
|||
| duplicate statements to reduce the overhead of the loop (default 1) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation get one extra space. Also the above one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above one need separate patch, since it have be backported to 3.6 and 3.5.
| @@ -301,6 +306,7 @@ def main(args=None, *, _wrap_timer=None): | |||
| print(__doc__, end=' ') | |||
| return 0 | |||
| setup = "\n".join(setup) or "pass" | |||
| stmt = "\n".join(args * duplicate) or "pass" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just always multiply number by duplicate here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If number is 0, it still is not auto-determined.
|
Could you please make a review @Haypo? |
| print("number is not divisible by duplicate.", | ||
| file=sys.stderr) | ||
| return 2 | ||
| number //= duplicate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm stuck at this line. I fail to review this change, because I don't understand why you want to divide the number of loops?
I expect that --repeat 5 --duplicate 2 will run the statement 10 times and divide the timing by 10. If you want to run the statement 2 times using --duplicate 2, just don't use --repeat, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--repeat is not related here. Perhaps you meant --number.
--number 10 runs the statement 10 times, in 10 iterations, 1 time per iteration. The total time is divided by 10.
--number 10 --duplicate 2 runs the statement 10 times, in 5 iterations, 2 time per iteration. The total time is divided by 10.
If the overhead of iterating is insignificant, both results are the same. Due to the overhead of iterating the second result is smaller.
At line 309 the original statement is multiplied by duplicate, therefore we should divide the number of iterating by duplicate. The total number of running the original statement is left the same.
|
Do you have other questions or comments @Haypo? |
|
This PR is stale because it has been open for 30 days with no activity. |
|
I recompiled but still get error: Fatal Python error: init_import_site: Failed to import the site module During handling of the above exception, another exception occurred: Traceback (most recent call last): cpython on timeit-duplicate [$?] via 🐍 v3.11.0a6+ |


https://bugs.python.org/issue30080