Skip to content
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

Add fast path in count_elements #120983

Merged
merged 1 commit into from
Jun 25, 2024
Merged

Conversation

rhettinger
Copy link
Contributor

A common case is that bound get() returns the default. In this case, the addition step can be skipped because we already know the result.

@rhettinger rhettinger added performance Performance or resource usage skip issue skip news labels Jun 25, 2024
@rhettinger rhettinger self-assigned this Jun 25, 2024
@rhettinger rhettinger merged commit 9b32b89 into python:main Jun 25, 2024
38 checks passed
@rhettinger rhettinger deleted the count_elements branch June 25, 2024 08:10
@eendebakpt
Copy link
Contributor

eendebakpt commented Jun 25, 2024

@rhettinger Do you have benchmarks for this change? I agree it makes the path for the first element faster, but for counting lots of elements it could make the code slower.

mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants