| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
|
Is there a benchmark where this shows a clear improvement? I'm struggling to find one :/ I tried various simple benchmarks locally, such as python -m timeit -n5 -r10 -s "from pathlib import Path" "list(Path('.').rglob('Lib/**/test_*.py'))"
I've no doubt that (?s:.) is much faster than [\s\S] in general, but here, I wonder if it makes a noticeable difference |
Sorry, something went wrong.
|
You can ask the OP. I guess that you can see some difference in match() for very long path. Simple example (in debug build): $ ./python -m timeit -s "from pathlib import Path; p = Path('a/'*1000)" "p.match('**/a')"
5000 loops, best of 5: 42.5 usec per loop
With this PR: 10000 loops, best of 5: 25.5 usec per loop |
Sorry, something went wrong.
Using a PGO-optimised build, I had to create an extremely long path for there to be a difference that wasn't just noise. But yeah, I can see a difference with this benchmark: main: >python -m timeit -n10 -r20 -s "from pathlib import Path; p = Path('a/'*1000000)" "p.match('**/a')"
Running PGUpdate|x64 interpreter...
10 loops, best of 20: 22.2 msec per loop
This PR: 10 loops, best of 20: 13 msec per loop |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM, though you may want to wait for @barneygale's feedback, since he knows the code here much better than me :)
Sorry, something went wrong.
There was a problem hiding this comment.
Looks fine to me, but perhaps worth noting that I'm intending to replace this code shortly - see #106703
That PR will only land in main, but this PR could be backported to 3.12 I think?
Sorry, something went wrong.
…1303) Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
…1303) Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
| Back | FazBrowse Home | New Git URL |
Regular expression pattern (?s:.) is much faster than [\s\S].