Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Speed-up math.dist() by 30%#9628

Merged
rhettinger merged 2 commits into
python:masterpython/cpython:masterfrom
rhettinger:math-fast-distrhettinger/cpython:math-fast-distCopy head branch name to clipboard
Sep 29, 2018
Merged

Speed-up math.dist() by 30%#9628
rhettinger merged 2 commits into
python:masterpython/cpython:masterfrom
rhettinger:math-fast-distrhettinger/cpython:math-fast-distCopy head branch name to clipboard

Conversation

@rhettinger

Copy link
Copy Markdown
Contributor

Manual type checking is much faster than the argument clinic equivalent.

--------- baseline ------------
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 95.5 nsec per loop
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 95.3 nsec per loop
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 95.5 nsec per loop

------ patched ------
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 67 nsec per loop
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 67.2 nsec per loop
$ pytime -r11 -s 'from math import dist' -s 'p=(1.1, 2.2)' -s 'q=(1.5, 2.5)' 'dist(p, q)'
5000000 loops, best of 11: 67.3 nsec per loop

Comment thread Modules/mathmodule.c Outdated
double diffs_on_stack[NUM_STACK_ELEMS];
double *diffs = diffs_on_stack;

if (!PyTuple_Check(p)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two ifs can be merged since their bodies are same.

@serhiy-storchaka serhiy-storchaka removed their assignment Sep 28, 2018
@rhettinger rhettinger merged commit df81015 into python:master Sep 29, 2018
@rhettinger rhettinger deleted the math-fast-dist branch September 29, 2018 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.