classification
Title: Speed-up statistics.fmean()
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steven.daprano Nosy List: rhettinger, steven.daprano
Priority: normal Keywords: patch

Created on 2019-06-05 05:24 by rhettinger, last changed 2019-06-05 16:49 by rhettinger. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13832 merged rhettinger, 2019-06-05 05:31
PR 13843 merged miss-islington, 2019-06-05 14:40
Messages (5)
msg344670 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-05 05:24
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
msg344726 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-05 14:40
New changeset 6c01ebcc0dfc6be22950fabb46bdc10dcb6202c9 by Raymond Hettinger in branch 'master':
bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832)
https://github.com/python/cpython/commit/6c01ebcc0dfc6be22950fabb46bdc10dcb6202c9
msg344733 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-05 15:18
New changeset 9ddb77741e041966d64739353393bcba33cc3bdd by Raymond Hettinger (Miss Islington (bot)) in branch '3.8':
bpo-37158: Simplify and speed-up statistics.fmean() (GH-13832) (GH-13843)
https://github.com/python/cpython/commit/9ddb77741e041966d64739353393bcba33cc3bdd
msg344746 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-06-05 16:45
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.)
msg344747 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-05 16:49
I can close it now :-)
History
Date User Action Args
2019-06-05 16:49:57rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg344747

stage: patch review -> resolved
2019-06-05 16:45:20steven.dapranosetmessages: + msg344746
2019-06-05 15:18:26rhettingersetmessages: + msg344733
2019-06-05 14:40:07miss-islingtonsetpull_requests: + pull_request13720
2019-06-05 14:40:00rhettingersetmessages: + msg344726
2019-06-05 05:31:44rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request13711
2019-06-05 05:24:04rhettingercreate