X Tutup
The Wayback Machine - https://web.archive.org/web/20250624063818/https://github.com/python/cpython/pull/1161
Skip to content

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

Closed

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 16, 2017

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Apr 16, 2017
@@ -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)
Copy link
Member

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.

Copy link
Member Author

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"
Copy link
Member

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?

Copy link
Member Author

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.

@serhiy-storchaka serhiy-storchaka requested a review from vstinner May 4, 2017 05:47
@serhiy-storchaka
Copy link
Member Author

Could you please make a review @Haypo?

print("number is not divisible by duplicate.",
file=sys.stderr)
return 2
number //= duplicate
Copy link
Member

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?

Copy link
Member Author

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.

@serhiy-storchaka
Copy link
Member Author

Do you have other questions or comments @Haypo?

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 19, 2022
@MaxwellDupre
Copy link
Contributor

I recompiled but still get error:
./python -m test -vvv test_timeit
Error processing line 1 of /home/me/.local/lib/python3.11/site-packages/sphinxcontrib_applehelp-1.0.2-py3.8-nspkg.pth:

Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "", line 186, in addpackage
File "", line 1, in
File "/home/me/Documents/cpython/Lib/importlib/init.py", line 51, in
_w_long = _bootstrap_external._w_long
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'importlib._bootstrap_external' has no attribute '_w_long'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 982, in exec_module
File "", line 616, in
File "", line 602, in main
File "", line 343, in addusersitepackages
File "", line 226, in addsitedir
File "", line 196, in addpackage
File "/home/me/Documents/cpython/Lib/traceback.py", line 5, in
import linecache
^^^^^^^^^^^^^^^^
File "/home/me/Documents/cpython/Lib/linecache.py", line 11, in
import tokenize
^^^^^^^^^^^^^^^
File "/home/me/Documents/cpython/Lib/tokenize.py", line 33, in
import re
^^^^^^^^^
File "/home/me/Documents/cpython/Lib/re.py", line 123, in
import sre_compile
^^^^^^^^^^^^^^^^^^
File "/home/me/Documents/cpython/Lib/sre_compile.py", line 17, in
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: SRE module mismatch

cpython on  timeit-duplicate [$?] via 🐍 v3.11.0a6+

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
X Tutup