Skip to content

gh-117431: Adapt str.find and friends to use the METH_FASTCALL calling convention #117468

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 3, 2024

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Apr 2, 2024

@erlend-aasland erlend-aasland marked this pull request as ready for review April 3, 2024 07:15
@erlend-aasland
Copy link
Contributor Author

Similar speedsups as with str.startswith and str.endswith:

# main
$ ./python.exe -m timeit -s "s = 'abcdef'" "s.count('a')"
5000000 loops, best of 5: 92.5 nsec per loop

# This PR
$ ./python.exe -m timeit -s "s = 'abcdef'" "s.count('a')"
10000000 loops, best of 5: 26.2 nsec per loop

@erlend-aasland
Copy link
Contributor Author

Thanks for the review, Inada-san.

@erlend-aasland erlend-aasland merged commit 7ecd55d into python:main Apr 3, 2024
@erlend-aasland erlend-aasland deleted the perf/str.find-and-friends branch April 3, 2024 15:59
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Apr 6, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…n#117468)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following methods are adapted:

- str.count
- str.find
- str.index
- str.rfind
- str.rindex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants