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

Simplify and speed-up math.hypot() and math.dist() #102734

Merged
merged 6 commits into from
Mar 15, 2023

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Mar 15, 2023

Apply the sumprod() DoubleLength functions to vector_norm() which is called by both hypot() and dist().

Baseline timing

% ./python.exe -m timeit -r11 -s 'from random import expovariate as r' -s 'from math import hypot' -s 'n=100' -s 'data = [r() for i in range(n)]' 'hypot(*data)'
500000 loops, best of 11: 579 nsec per loop

Timing with PR

% ./python.exe -m timeit -r11 -s 'from random import expovariate as r' -s 'from math import hypot' -s 'n=100' -s 'data = [r() for i in range(n)]' 'hypot(*data)'
500000 loops, best of 11: 476 nsec per loop

Timing with PR if fma() is not used

% ./python.exe -m timeit -r11 -s 'from random import expovariate as r' -s 'from math import hypot' -s 'n=100' -s 'data = [r() for i in range(n)]' 'hypot(*data)'
500000 loops, best of 11: 531 nsec per loop

@rhettinger rhettinger merged commit 0a22aa0 into python:main Mar 15, 2023
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes performance Performance or resource usage skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants