close
Skip to content

Speed up counting in statistics.fmean()#148875

Open
rhettinger wants to merge 2 commits intopython:mainfrom
rhettinger:fmean_optimization
Open

Speed up counting in statistics.fmean()#148875
rhettinger wants to merge 2 commits intopython:mainfrom
rhettinger:fmean_optimization

Conversation

@rhettinger
Copy link
Copy Markdown
Contributor

Implement a faster counting strategy that avoids tuple creation, indexing, and destruction.

Baseline timing:

% ./python.exe -m timeit -s 'from statistics import fmean' 'fmean(iter(range(10**3)))'
20000 loops, best of 5: 18.7 usec per loop

After the PR:

% ./python.exe -m timeit -s 'from statistics import fmean' 'fmean(iter(range(10**3)))'
20000 loops, best of 5: 11.4 usec per loop

Comment thread Lib/statistics.py Outdated
Co-authored-by: Shrey Naithani <shrey.naithani@shelllite.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants