Skip to content

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 <[email protected]>
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

@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