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-117648: Improve performance of os.join by replacing map with a direct method …#117654

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

Conversation

@nineteendo
Copy link
Contributor

@nineteendonineteendo commentedApr 8, 2024
edited
Loading

…call

Benchmark

ntpath.py

script
::test.bat@echooffecho1 item&& python -m timeit -s"import before.ntpath""before.ntpath.join('foo')"&& python -m timeit -s"import after.ntpath""after.ntpath.join('foo')"echo10 items&& python -m timeit -s"import before.ntpath; paths = ['foo'] * 10""before.ntpath.join(*paths)"&& python -m timeit -s"import after.ntpath; paths = ['foo'] * 10""after.ntpath.join(*paths)"echo100 items&& python -m timeit -s"import before.ntpath; paths = ['foo'] * 100""before.ntpath.join(*paths)"&& python -m timeit -s"import after.ntpath; paths = ['foo'] * 100""after.ntpath.join(*paths)"
1 item500000 loops, best of 5: 699 nsec per loop # before500000 loops, best of 5: 612 nsec per loop # after# -> 1.14x faster10 items50000 loops, best of 5: 5.47 usec per loop # before50000 loops, best of 5: 5.18 usec per loop # after# -> 1.06x faster100 items5000 loops, best of 5: 54.6 usec per loop # before5000 loops, best of 5: 51.9 usec per loop # after# -> 1.05x faster

posixpath.py

script
# test.shecho 1 item&& python -m timeit -s"import before.posixpath""before.posixpath.join('foo')"&& python -m timeit -s"import after.posixpath""after.posixpath.join('foo')"echo 10 items&& python -m timeit -s"import before.posixpath; paths = ['foo'] * 10""before.posixpath.join(*paths)"&& python -m timeit -s"import after.posixpath; paths = ['foo'] * 10""after.posixpath.join(*paths)"echo 100 items&& python -m timeit -s"import before.posixpath; paths = ['foo'] * 100""before.posixpath.join(*paths)"&& python -m timeit -s"import after.posixpath; paths = ['foo'] * 100""after.posixpath.join(*paths)"
1 item1000000 loops, best of 5: 325 nsec per loop # before1000000 loops, best of 5: 241 nsec per loop # after# -> 1.35x faster10 items100000 loops, best of 5: 3.33 usec per loop # before100000 loops, best of 5: 3.32 usec per loop # after# -> no difference100 items10000 loops, best of 5: 33.8 usec per loop # before10000 loops, best of 5: 34.1 usec per loop # after# -> no difference

…callCo-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@nineteendonineteendo marked this pull request as ready for reviewApril 9, 2024 05:56
@erlend-aaslanderlend-aasland added the performancePerformance or resource usage labelApr 9, 2024
Copy link
Contributor

@erlend-aaslanderlend-aasland left a comment

Choose a reason for hiding this comment

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

The change itself is minimal, code readability/maintainability is not affected, and the speedup seems good enough to warrant an approval.

I still recommend redirecting your enthusiasm towards triaging the existing issues in the bug-tracker and helping fixing real bugs instead of looking for micro-optimisations. See my comment#117634 (comment).

@erlend-aaslanderlend-aasland merged commit99852d9 intopython:mainApr 9, 2024
@nineteendonineteendo deleted the speedup-os.path.join-2 branchApril 9, 2024 08:36
diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 17, 2024
Replace map() with a method call in the loop body.Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

Assignees

No one assigned

Labels

performancePerformance or resource usage

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@nineteendo@erlend-aasland

[8]ページ先頭

©2009-2025 Movatter.jp