-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Specify time unit for timeit CLI #63183
Comments
Just an idea. Currently the timeit module in command line automatically choice most appropriate time unit for human readable output. But this makes the output less machine readable. I propose to add new option which specifies fixed time unit (usec, msec, sec). |
If you want the output to be machine readable, better go the full way and add a --json option, IMO. |
My 2 cents - I'd split timeit.main function into processing part and argument parsing + data printing part so that you could use Python to call the first one to get the actual results (timings, numbers of loops etc.) and then present the data to the outside world in any needed format - no text parsing needed. |
I created a patch that allows users to specify a time unit output using the "-u" flag. Example usage: python -m timeit -u "msec" '"-".join(str(n) for n in range(100))'
python -m timeit -u "sec" '"-".join(str(n) for n in range(100))'
You can specify msec, sec, or usec. I am also interested in having a JSON option as mentioned by Antoine. Any thoughts? |
Updated patch to include unit tests. |
Just wanted to check to see if there was anything else I should do regarding this issue. |
Implemented proposed changes to patch. Simplified "for-loop" and implemented invalid input test. |
Incorporated updates suggested by serhiy.storchaka |
It will be better to write error message to sys.stderr (see test_main_exception). |
Updated patch to log to stderr. |
Added newline after error message. |
The patch is doubled. |
Whoops. Sorry about that. Super embarrassing. |
Re-uploaded the patch to remove duplication. |
Besides too long line with sys.stderr.write last patch LGTM. |
Ah, I forgot. This feature should be documented in Doc/library/timeit.rst. |
Updated documentation and fixed a few lines that were too long. |
Just wanted to check in and see if the documentation change I made is sufficient. I tried to copy the other entries for the command line arguments. Let me know if I can improve it in any way. |
LGTM. |
What needs to be done to close this one out? |
This feature is for Python 3.5. I think, we will not commit anything to Python 3.5 until Python 3.4 branch is created (in other world, released). So, be patient. :) |
The branch appears to exist now. |
Anything else need to be done on this patch? |
1 similar comment
Anything else need to be done on this patch? |
I've added a couple of comments on Rietveld. |
New changeset 1ebf8d5b7d60 by Robert Collins in branch 'default': |
New changeset ed34dd00405e by Robert Collins in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: