[issue36781] Optimize sum() for bools

2019-09-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Well, it is good for people who already sum bools. But if you are concerned about microoptimization, sum(1 for ... if ...) can be better variant. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.9

[issue36781] Optimize sum() for bools

2019-09-10 Thread Vedran Čačić
Vedran Čačić added the comment: I don't think anything _bad_ can happen with that optimization, if it's already written. And people (me included) do like to write shorter expressions instead of longer ones. -- nosy: +veky ___ Python tracker

[issue36781] Optimize sum() for bools

2019-09-10 Thread Dino Viehland
Dino Viehland added the comment: Sorry, it seemed like a perfectly reasonable change when I was looking at the PR! -- ___ Python tracker ___

[issue36781] Optimize sum() for bools

2019-09-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Oh, I was going to withdraw this. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue36781] Optimize sum() for bools

2019-09-10 Thread Dino Viehland
Dino Viehland added the comment: New changeset 88bdb9280b251d753f1b1c8d9183de0fff003622 by Dino Viehland (Serhiy Storchaka) in branch 'master': bpo-36781: Optimize sum() for bools. (#13074) https://github.com/python/cpython/commit/88bdb9280b251d753f1b1c8d9183de0fff003622 -- nosy:

[issue36781] Optimize sum() for bools

2019-06-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I am not sure that this optimization should be added. sum(pred(x) for x in data) will be always slower than sum(1 for x in data if pred(x)) because more items is passed to sun() in the former case. It can be considered as an anti-pattern. --

[issue36781] Optimize sum() for bools

2019-05-05 Thread Josh Rosenberg
Change by Josh Rosenberg : -- nosy: +josh.r ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue36781] Optimize sum() for bools

2019-05-05 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- keywords: +patch pull_requests: +13010 stage: -> patch review ___ Python tracker ___ ___

[issue36781] Optimize sum() for bools

2019-05-03 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : To count the number of items that satisfy certain condition you can use either sum(1 for x in data if pred(x)) or sum(pred(x) for x in data) where pred(x) is a boolean expression. The latter case is shorter but slower. There are two causes for