Visitar URL original
Add fast path in count_elements by rhettinger · Pull Request #120983 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260304170657/https://github.com/python/cpython/pull/120983
Skip to content
/ cpython Public

Add fast path in count_elements#120983

Merged
rhettinger merged 1 commit intopython:mainfrom
rhettinger:count_elements
Jun 25, 2024
Merged

Add fast path in count_elements#120983
rhettinger merged 1 commit intopython:mainfrom
rhettinger:count_elements

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
@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