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

timeit: Use thousands separators and print number of loops per second #63175

Closed
jstasiak mannequin opened this issue Sep 8, 2013 · 18 comments
Closed

timeit: Use thousands separators and print number of loops per second #63175

jstasiak mannequin opened this issue Sep 8, 2013 · 18 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jstasiak
Copy link
Mannequin

jstasiak mannequin commented Sep 8, 2013

BPO 18975
Nosy @tim-one, @pitrou, @ezio-melotti, @bitdancer, @serhiy-storchaka, @jstasiak, @csabella
Files
  • timeit.patch
  • timeit-v2.patch
  • timeit-v3-actual-changes.patch
  • timeit-v3-pep8.patch
  • timeit-v3-actual-changes-no-separators.patch
  • timeit-v4-actual-changes.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 = None
    created_at = <Date 2013-09-08.16:00:31.283>
    labels = ['type-feature', 'library']
    title = 'timeit: Use thousands separators and print number of loops per second'
    updated_at = <Date 2017-08-27.13:46:09.639>
    user = 'https://github.com/jstasiak'

    bugs.python.org fields:

    activity = <Date 2017-08-27.13:46:09.639>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-09-08.16:00:31.283>
    creator = 'jstasiak'
    dependencies = []
    files = ['31672', '31673', '31683', '31684', '31786', '31792']
    hgrepos = []
    issue_num = 18975
    keywords = ['patch']
    message_count = 18.0
    messages = ['197274', '197276', '197282', '197286', '197287', '197303', '197305', '197308', '197314', '197315', '197316', '197852', '197858', '197869', '197878', '197882', '197885', '300916']
    nosy_count = 7.0
    nosy_names = ['tim.peters', 'pitrou', 'ezio.melotti', 'r.david.murray', 'serhiy.storchaka', 'jstasiak', 'cheryl.sabella']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18975'
    versions = ['Python 3.4']

    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 8, 2013

    This patch includes:

    • making code more PEP-8-compatible and refactoring it a bit
    • printing number of loops per second when using command line interface
    • using thousands separators when printing numbers of loops (also in command line interface)
    • changing examples in the module documentation

    The output is changed from this:

    10000 loops, best of 3: 40.3 usec per loop
    

    to that:

    10,000 loops, best of 3: 34.6 usec per loop, 28,870.783/s
    

    I'm still not sure about details of "28,870.783/s" part:

    • whether it should always include the fractional part (in this example it doesn't make any sense)
    • maybe it should say "loops/s" rather than just "/s"

    @jstasiak jstasiak mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 8, 2013
    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 8, 2013

    Oops, forgot to patch the tests, please find correct patch attached.

    @ezio-melotti
    Copy link
    Member

    I personally dislike the "," as thousands separator, and if a separator is added at all I would prefer a space as defined in the SI standard0.

    The PEP-8 changes should also me moved to a separate patch IMHO; the other changes are OK grouped together.

    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 8, 2013

    I agree with both notes. Splitting the patch won't be a problem.

    As much as I don't fancy "," as thousands separator either - I just used what's in the standard library but I'll think about the best way of putting spaces there.

    @pitrou
    Copy link
    Member

    pitrou commented Sep 8, 2013

    I personally dislike the "," as thousands separator, and if a
    separator is added at all I would prefer a space as defined in the SI
    standard[0].

    Then you really want a non-breaking space ;-)

    (as a French person who's used to commas as decimal points, count me in the "commas as thousands separators are confusing" camp ;-))

    • whether it should always include the fractional part (in this
      example it doesn't make any sense)

    Indeed, it probably doesn't make sense unless the number is < 100.
    I would also put that information inside parentheses, as it is redundant with the per-loop timing.

    • maybe it should say "loops/s" rather than just "/s"

    Yeah.

    @serhiy-storchaka
    Copy link
    Member

    I'm afraid the adding any separators will make some people angry. With a comma or space it no more a valid number in Python and many other languages and can't be copy/pasted and parsed.

    Actually I sometimes use small shell scripts to run "python -m timeit" and parsing results with grep, sed and awk. It is easer in simplest cases than writing it on Python (especially when different Python binaries used).

    I'm -0,1.

    @bitdancer
    Copy link
    Member

    I'm with Serhiy on this. So if separators are added, I would say they *must* be optional. Presumably if they are added they should be locale dependent :) All of which may well make it more complicated than it is worth.

    @tim-one
    Copy link
    Member

    tim-one commented Sep 8, 2013

    -1 from me, and I'm a comma-loving American ;-)

    I'm sure lots of code in the wild parses this output - Serhiy isn't the only one doing it.

    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 8, 2013

    To me the point of this patch is adding number of loops per second information - using thousands separators was just an addition which I'm happy to drop.

    Please find attached 2 patches:

    • one containing actual changes - loops per second added, fractional part is printed when the number is less than 100, space is used as thousands separator; old part of the message is not affected
    • one containing PEP-8 reformatting

    So:

    10000 loops, best of 3: 34.6 usec per loop (28 870 loops/s)
    

    @pitrou
    Copy link
    Member

    pitrou commented Sep 8, 2013

    So:

    10000 loops, best of 3: 34.6 usec per loop (28 870 loops/s)
    

    Looks fine to me (though having a decimal space at the right and not at
    the left looks a bit weird).

    @bitdancer
    Copy link
    Member

    I do not find a space to be an acceptable separator, sorry.

    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 16, 2013

    Antoine: I agree that it does look weird to have thousands separators at one place and not at the other but IMO it's still slightly better - the number formatted with separators is simply more readable that separator-less one.

    R. David Murray: what's the acceptable separator then? Modifying it to be locale-aware would make it inconsistent with the rest of the output (which, admittedly, is also the case with introducing space separator, dot still is the fraction separator though).

    I modified my patch to not have the separators at all, please find timeit-v3-actual-changes-no-separators.patch - if that's the condition for accepting this patch then so be it - the description of the patch would be "print number of loops per second" and the example output is:

    10000 loops, best of 3: 34.6 usec per loop (28870 loops/s)

    @bitdancer
    Copy link
    Member

    My vote is no separators. But I'm just one vote :)

    @serhiy-storchaka
    Copy link
    Member

    My vote is no separators. But I'm just one vote :)

    Seconded.

    @pitrou
    Copy link
    Member

    pitrou commented Sep 16, 2013

    I'm fine with the change too. Tim, what do you think?

    Speaking of which, some examples were really done with an old machine:

        $ python -m timeit 'try:' '  str.__bool__' 'except AttributeError:' '  pass'
    -   100000 loops, best of 3: 15.7 usec per loop
    +   1000000 loops, best of 3: 0.701 usec per loop (1425528 loops/s)

    :-)

    @serhiy-storchaka
    Copy link
    Member

    Inconsistency: "sec per loop" vs. "loops/s".

    @jstasiak
    Copy link
    Mannequin Author

    jstasiak mannequin commented Sep 16, 2013

    That's right, I was actually wondering about it few minutes before you pointed it out. Find new patch attached.

    @csabella
    Copy link
    Contributor

    Reviewing this patch, it appears that the PEP-8 changes to timeit.py are already in the source and the discussion of the thousands separator is no longer an issue with the underscore changes in 3.6 (meaning underscore now seems the way to separate digits in large numbers, although it seems the vote was to remove all separators from timeit anyway).

    That would leave the loops per second request the only one still needed from this patch. But, with the subsequent change of selecting the time unit in timeit, perhaps this patch would need to be modified to print 'loops per {timeunit}'?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants