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-117641: Use set comprehension forposixpath.commonpath()#117652

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

Benchmark

script
# test.shecho 1 item&& python -m timeit -s"import before.posixpath""before.posixpath.commonpath(['foo'])"&& python -m timeit -s"import after.posixpath""after.posixpath.commonpath(['foo'])"echo 10 items&& python -m timeit -s"import before.posixpath""before.posixpath.commonpath(['foo'] * 10)"&& python -m timeit -s"import after.posixpath""after.posixpath.commonpath(['foo'] * 10)"echo 100 items&& python -m timeit -s"import before.posixpath""before.posixpath.commonpath(['foo'] * 100)"&& python -m timeit -s"import after.posixpath""after.posixpath.commonpath(['foo'] * 100)"
1 item200000 loops, best of 5: 1.81 usec per loop # before200000 loops, best of 5: 1.47 usec per loop # after# -> 1.23x faster10 items50000 loops, best of 5: 5.25 usec per loop # before50000 loops, best of 5: 4.66 usec per loop # after# -> 1.13x faster100 items5000 loops, best of 5: 39.9 usec per loop # before10000 loops, best of 5: 37.3 usec per loop # after# -> 1.07x faster

@nineteendonineteendo marked this pull request as ready for reviewApril 8, 2024 19:31
@nineteendo
Copy link
ContributorAuthor

@serhiy-storchaka, do you have suggestions here?

@serhiy-storchaka
Copy link
Member

I understand the use of set comprehension instead of generator, it can add a tiny speed up. But why get rid of unpack?

@nineteendo
Copy link
ContributorAuthor

nineteendo commentedApr 16, 2024
edited
Loading

I wanted to make the code more readable. But I'll revert it as it's slower:

deftest1(paths):sep='/'try:isabs,= {p.startswith(sep)forpinpaths}exceptValueError:raiseValueError("Can't mix absolute and relative paths")fromNoneprefix=sepifisabselsesep[:0]returnprefixdeftest2(paths):sep='/'iflen({p.startswith(sep)forpinpaths})!=1:raiseValueError("Can't mix absolute and relative paths")prefix=sepifpaths[0].startswith(sep)elsesep[:0]returnprefix
wannes@Stefans-iMac Desktop % python -m timeit -s"import test""test.test1(['foo'])"&& python -m timeit -s"import test""test.test2(['foo'])"1000000 loops, best of 5: 369 nsec per loop# unpack500000 loops, best of 5: 451 nsec per loop# no unpack# -> 1.22x slower

@nineteendo
Copy link
ContributorAuthor

@erlend-aasland, do you think this can be merged now? I addressed serhiy-storchaka's question.

@erlend-aasland
Copy link
Contributor

erlend-aasland commentedApr 17, 2024
edited
Loading

@erlend-aasland, do you think this can be merged now? I addressed serhiy-storchaka's question.

I'll run PGO benchmarks for the updated PR first.

UPDATE: I'm getting between 5% and 20% speedups, similar to the speedup in the PR description.

@nineteendo
Copy link
ContributorAuthor

@erlend-aasland, could you merge it? It has been approved by serhiy.

@erlend-aasland
Copy link
Contributor

@nineteendo: yes, it was on my list; there is no need for the extra ping. There is no hurry; I'll land it tomorrow morning. Please avoid unneeded pings.

@erlend-aaslanderlend-aasland self-assigned thisApr 17, 2024
@nineteendo
Copy link
ContributorAuthor

Thanks.

Please avoid unneeded pings.

Sorry, sometimes I get no response, and then I don't know if my message was even read.

erlend-aasland reacted with thumbs up emoji

@erlend-aaslanderlend-aasland merged commitb848b94 intopython:mainApr 18, 2024
@nineteendonineteendo deleted the speedup-posixpath.commonpath branchApril 18, 2024 07:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eendebakpteendebakpteendebakpt left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

+1 more reviewer

@blhsingblhsingblhsing left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@erlend-aaslanderlend-aasland

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@nineteendo@serhiy-storchaka@erlend-aasland@eendebakpt@blhsing

[8]ページ先頭

©2009-2025 Movatter.jp