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

Speed-up statistics.fmean() #81339

Closed
rhettinger opened this issue Jun 5, 2019 · 5 comments
Closed

Speed-up statistics.fmean() #81339

rhettinger opened this issue Jun 5, 2019 · 5 comments
Assignees
Labels
3.8 (EOL) end of life 3.9 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@rhettinger
Copy link
Contributor

BPO 37158
Nosy @rhettinger, @stevendaprano
PRs
  • bpo-37158: Simplify and speed-up statistics.fmean() #13832
  • [3.8] bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832) #13843
  • 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 = 'https://github.com/stevendaprano'
    closed_at = <Date 2019-06-05.16:49:57.163>
    created_at = <Date 2019-06-05.05:24:04.274>
    labels = ['3.8', 'library', '3.9', 'performance']
    title = 'Speed-up statistics.fmean()'
    updated_at = <Date 2019-06-05.16:49:57.162>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2019-06-05.16:49:57.162>
    actor = 'rhettinger'
    assignee = 'steven.daprano'
    closed = True
    closed_date = <Date 2019-06-05.16:49:57.163>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2019-06-05.05:24:04.274>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37158
    keywords = ['patch']
    message_count = 5.0
    messages = ['344670', '344726', '344733', '344746', '344747']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'steven.daprano']
    pr_nums = ['13832', '13843']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue37158'
    versions = ['Python 3.8', 'Python 3.9']

    @rhettinger
    Copy link
    Contributor Author

    fmean() can be sped-up by converting count() from a function to a generator and by using enumerate() to do the counting.

    -- Baseline ---

    $ ./python.exe -m timeit -r11 -s 'from statistics import fmean' -s 'data=list(map(float, range(1000)))' 'fmean(iter(data))'
    2000 loops, best of 11: 108 usec per loop

    -- Patched --
    $ ./python.exe -m timeit -r11 -s 'from statistics import fmean' -s 'data=list(map(float, range(1000)))' 'fmean(iter(data))'
    5000 loops, best of 11: 73.1 usec per loop

    @rhettinger rhettinger added 3.8 (EOL) end of life 3.9 only security fixes labels Jun 5, 2019
    @rhettinger rhettinger added stdlib Python modules in the Lib dir performance Performance or resource usage labels Jun 5, 2019
    @rhettinger
    Copy link
    Contributor Author

    New changeset 6c01ebc by Raymond Hettinger in branch 'master':
    bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832)
    6c01ebc

    @rhettinger
    Copy link
    Contributor Author

    New changeset 9ddb777 by Raymond Hettinger (Miss Islington (bot)) in branch '3.8':
    bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832) (GH-13843)
    9ddb777

    @stevendaprano
    Copy link
    Member

    Nice! On my computer, I get about 30% speed up. Thanks Raymond.

    The two PRs are status "merged". Does this mean we can close this ticket or is there more to do? (The git workflow is still a mystery to me.)

    @rhettinger
    Copy link
    Contributor Author

    I can close it now :-)

    @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
    3.8 (EOL) end of life 3.9 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants