-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Raise use_a_generator for sum()
, max()
, min()
#6595
Raise use_a_generator for sum()
, max()
, min()
#6595
Conversation
The benchmark result could be counterintuitive for small sum/max/min, see #3309 (comment). Depending on the results of a benchmark we'd need to use 'consider-using-generator' or 'use-a-generator'. |
Pull Request Test Coverage Report for Build 2316079191
💛 - Coveralls |
I will do benchmarking. Just a comment about it - I think it is not 100% truth. In attached PEP using generator is recommended. Doing microbenchmarks can be misleading - e.g. in python 3.9 generator version can be slower but in 3.11 it can be opposite:
I think we should follow best practises instead of tightly following microbenchmarks. [1] https://docs.python.org/3.11/whatsnew/3.11.html#summary-release-highlights |
|
Co-authored-by: Daniël van Noord <[email protected]>
I agree with the sentiment of the benchmark not being perfect. In fact, that's my bad for suggesting it, the decision for any/all vs list/set/dict was not taken based on the benchmark but based on the theory that a generator for all/any will be cutting the execution tree in most case so it will be faster, sometime by a lot. I think |
I think it should be
|
Follow-up to #6595 Co-authored-by: Daniël van Noord <[email protected]>
Type of Changes
Description
Based on https://peps.python.org/pep-0289/ also
sum()
,max()
,min()
should avoid usinglists. Using generator, the memory is not allocated for all items but the items are processed lazily.