[issue23509] Speed up Counter operators
Serhiy Storchaka
report at bugs.python.org
Thu Feb 26 09:53:28 CET 2015
Serhiy Storchaka added the comment:
Applied optimizations:
1) Used cached get() method instead of indexing. This optimization already was used in update() and subtract().
2) _keep_positive() is optimized for the case when most counts are not positive (common case for substraction and intersection).
3) __add__ and __or__ are defined via inplace operations which are faster (due to fast copying and _keep_positive()).
4) Inlined and simplified the code for __pos__ and __neg__.
May be following optimization can be made by implementing _keep_positive() in C.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23509>
_______________________________________
More information about the Python-bugs-list
mailing list