Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

GH-112727: Speed uppathlib.Path.absolute()#112728

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
barneygale merged 4 commits intopython:mainfrombarneygale:speed-up-path-absolute
Dec 4, 2023

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedDec 4, 2023
edited by bedevere-appbot
Loading

Use_from_parsed_parts() to create a pre-joined/pre-parsed path, rather than passing multiple arguments towith_segments()

Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, ratherthan passing multiple arguments to `with_segments()`
@barneygale
Copy link
ContributorAuthor

barneygale commentedDec 4, 2023
edited
Loading

1.5x speedup for paths with tail segments:

$ ./python -m timeit -s "from pathlib import Path" "str(Path().absolute())"100000 loops, best of 5: 3.82 usec per loop  # before 50000 loops, best of 5: 3.9  usec per loop  # after$ ./python -m timeit -s "from pathlib import Path" "str(Path('foo').absolute())"50000 loops, best of 5: 9.79 usec per loop  # before50000 loops, best of 5: 6.2  usec per loop  # after$ ./python -m timeit -s "from pathlib import Path" "str(Path('foo', 'bar').absolute())"20000 loops, best of 5: 11.5  usec per loop  # before50000 loops, best of 5:  7.54 usec per loop  # after

It would be interesting to also test the performance ofstr(WindowsPath('c:foo').absolute()) andstr(WindowsPath('/foo').absolute()), but I don't have a Windows box to hand.

@AlexWaygood
Copy link
Member

Big speedups on Windows!

Onmain:

>python -m timeit -s "from pathlib import WindowsPath" "str(WindowsPath('c:foo').absolute())"Running PGUpdate|x64 interpreter...50000 loops, best of 5: 9.92 usec per loop>python -m timeit -s "from pathlib import WindowsPath" "str(WindowsPath('/foo').absolute())"Running PGUpdate|x64 interpreter...50000 loops, best of 5: 8.32 usec per loop

With PR:

>python -m timeit -s "from pathlib import WindowsPath" "str(WindowsPath('c:foo').absolute())"Running PGUpdate|x64 interpreter...50000 loops, best of 5: 6.01 usec per loop>python -m timeit -s "from pathlib import WindowsPath" "str(WindowsPath('/foo').absolute())"Running PGUpdate|x64 interpreter...50000 loops, best of 5: 4.97 usec per loop

(Timings done using a reasonably fresh PGO-optimised build)

barneygale reacted with thumbs up emoji

@AlexWaygood
Copy link
Member

I can also repro all your reported speedups from#112728 (comment)!

barneygale reacted with hooray emoji

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM

barneygale reacted with thumbs up emoji
@barneygale
Copy link
ContributorAuthor

Thanks tons!

AlexWaygood reacted with heart emoji

@barneygalebarneygaleenabled auto-merge (squash)December 4, 2023 23:13
@barneygalebarneygale merged commit304a1b3 intopython:mainDec 4, 2023
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, ratherthan passing multiple arguments to `with_segments()`Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, ratherthan passing multiple arguments to `with_segments()`Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

Assignees
No one assigned
Labels
performancePerformance or resource usagetopic-pathlib
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@barneygale@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp