Skip to content
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

Closed
serhiy-storchaka opened this issue Sep 8, 2013 · 27 comments
Closed

Specify time unit for timeit CLI #63183

serhiy-storchaka opened this issue Sep 8, 2013 · 27 comments
Labels
easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 18983
Nosy @tim-one, @birkenfeld, @pitrou, @rbtcollins, @ezio-melotti, @berkerpeksag, @serhiy-storchaka, @vajrasky, @jstasiak, @pquentin
Files
  • issue18983.patch
  • issue18983.patch
  • issue18983_v2.patch
  • issue18983_v3.patch
  • issue18983_v4.patch
  • issue18983_v5.patch
  • issue18983_v5.patch
  • issue18983_v6.patch
  • 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:

    assignee = None
    closed_at = <Date 2015-03-17.21:01:41.998>
    created_at = <Date 2013-09-08.21:15:56.832>
    labels = ['easy', 'type-feature', 'library']
    title = 'Specify time unit for timeit CLI'
    updated_at = <Date 2015-03-17.21:01:41.997>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-03-17.21:01:41.997>
    actor = 'rbcollins'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-03-17.21:01:41.998>
    closer = 'rbcollins'
    components = ['Library (Lib)']
    creation = <Date 2013-09-08.21:15:56.832>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['32862', '32874', '33058', '33064', '33066', '33067', '33068', '33095']
    hgrepos = []
    issue_num = 18983
    keywords = ['patch', 'easy']
    message_count = 27.0
    messages = ['197322', '197333', '197345', '204541', '204606', '205612', '205697', '205720', '205723', '205731', '205736', '205737', '205738', '205914', '205922', '205923', '205931', '206834', '206869', '207990', '207995', '216024', '226093', '233346', '233348', '238337', '238338']
    nosy_count = 13.0
    nosy_names = ['tim.peters', 'georg.brandl', 'pitrou', 'rbcollins', 'ezio.melotti', 'python-dev', 'berker.peksag', 'serhiy.storchaka', 'Vincentdavis', 'vajrasky', 'jstasiak', 'Julian.Gindi', 'Quentin.Pradet']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18983'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    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).

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir easy type-feature A feature request or enhancement labels Sep 8, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Sep 8, 2013

    If you want the output to be machine readable, better go the full way and add a --json option, IMO.

    @jstasiak
    Copy link
    Mannequin

    jstasiak mannequin commented Sep 9, 2013

    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.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Nov 26, 2013

    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))'

    > 10000 loops, best of 3: 0.156 msec per loop

    python -m timeit -u "sec" '"-".join(str(n) for n in range(100))'

    > 10000 loops, best of 3: 0.000159 sec per loop

    You can specify msec, sec, or usec. I am also interested in having a JSON option as mentioned by Antoine. Any thoughts?

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Nov 27, 2013

    Updated patch to include unit tests.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 8, 2013

    Just wanted to check to see if there was anything else I should do regarding this issue.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 9, 2013

    Implemented proposed changes to patch. Simplified "for-loop" and implemented invalid input test.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 9, 2013

    Incorporated updates suggested by serhiy.storchaka

    @serhiy-storchaka
    Copy link
    Member Author

    It will be better to write error message to sys.stderr (see test_main_exception).

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 9, 2013

    Updated patch to log to stderr.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 9, 2013

    Added newline after error message.

    @serhiy-storchaka
    Copy link
    Member Author

    The patch is doubled.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 9, 2013

    Whoops. Sorry about that. Super embarrassing.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 11, 2013

    Re-uploaded the patch to remove duplication.

    @serhiy-storchaka
    Copy link
    Member Author

    Besides too long line with sys.stderr.write last patch LGTM.

    @serhiy-storchaka
    Copy link
    Member Author

    Ah, I forgot. This feature should be documented in Doc/library/timeit.rst.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 11, 2013

    Updated documentation and fixed a few lines that were too long.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 22, 2013

    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.

    @serhiy-storchaka
    Copy link
    Member Author

    LGTM.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Jan 13, 2014

    What needs to be done to close this one out?

    @vajrasky
    Copy link
    Mannequin

    vajrasky mannequin commented Jan 13, 2014

    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. :)

    @pquentin
    Copy link
    Mannequin

    pquentin mannequin commented Apr 13, 2014

    The branch appears to exist now.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Aug 29, 2014

    Anything else need to be done on this patch?

    1 similar comment
    @Vincentdavis
    Copy link
    Mannequin

    Vincentdavis mannequin commented Jan 3, 2015

    Anything else need to be done on this patch?

    @berkerpeksag
    Copy link
    Member

    I've added a couple of comments on Rietveld.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 17, 2015

    New changeset 1ebf8d5b7d60 by Robert Collins in branch 'default':
    Issue bpo-18983: Allow selection of output units in timeit.
    https://hg.python.org/cpython/rev/1ebf8d5b7d60

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 17, 2015

    New changeset ed34dd00405e by Robert Collins in branch 'default':
    Fix patch attribution for bpo-18983.
    https://hg.python.org/cpython/rev/ed34dd00405e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants