Uh oh!
There was an error while loading. Please reload this page.
gh-117641: Use set comprehension for posixpath.commonpath() - #117652
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nineteendo
commented
Apr 13, 2024
@serhiy-storchaka, do you have suggestions here? |
serhiy-storchaka
commented
Apr 15, 2024
I understand the use of set comprehension instead of generator, it can add a tiny speed up. But why get rid of unpack? |
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]
returnprefixwannes@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 # unpack
500000 loops, best of 5: 451 nsec per loop # no unpack# -> 1.22x slower |
nineteendo
commented
Apr 17, 2024
@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
commented
Apr 17, 2024
@erlend-aasland, could you merge it? It has been approved by serhiy. |
erlend-aasland
commented
Apr 17, 2024
@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. |
nineteendo
commented
Apr 17, 2024
Thanks.
Sorry, sometimes I get no response, and then I don't know if my message was even read. |
Benchmark
script
posixpath.commonpath()#117641