Skip to content

gh-112405: Optimise pathlib.Path.relative_to #112406

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

Merged
merged 4 commits into from
Nov 26, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Nov 25, 2023

On main (Windows machine, PGO-optimised build):

>python -m timeit -s "from pathlib import Path; p = Path('a/b/c/d/e/f/g')" "p.relative_to('a/b/c/d')"
Running PGUpdate|x64 interpreter...
10000 loops, best of 5: 28.7 usec per loop

With this PR:

>python -m timeit -s "from pathlib import Path; p = Path('a/b/c/d/e/f/g')" "p.relative_to('a/b/c/d')"
Running PGUpdate|x64 interpreter...
20000 loops, best of 5: 19.5 usec per loop

Fixes #112405

@AlexWaygood AlexWaygood added type-feature A feature request or enhancement performance Performance or resource usage topic-pathlib labels Nov 25, 2023
@AlexWaygood
Copy link
Member Author

itertools is an extremely fast import; this makes ~no difference to pathlib's import time :)

Copy link
Contributor

@itamaro itamaro left a comment

Choose a reason for hiding this comment

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

nice win!

Co-authored-by: Itamar Oren <itamarost@gmail.com>
Copy link
Contributor

@barneygale barneygale left a comment

Choose a reason for hiding this comment

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

Lovely stuff

…OtzxC.rst

Co-authored-by: Barney Gale <barney.gale@gmail.com>
@AlexWaygood
Copy link
Member Author

Thanks both! :D

@AlexWaygood AlexWaygood enabled auto-merge (squash) November 26, 2023 15:40
@AlexWaygood AlexWaygood merged commit 418d585 into python:main Nov 26, 2023
@AlexWaygood AlexWaygood deleted the pathlib-itertools branch November 26, 2023 15:56
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage topic-pathlib type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimise pathlib.Path.relative_to()
3 participants