3 ms·
Right, that's what I meant. If the C code has to cope with dynamic typing anyway, there might be little scope to speed things up. The same isn't true for, say,
by MaxBarraclough 6y ago
Right, that's what I meant. If the C code has to cope with dynamic typing anyway, there might be little scope to speed things up.
The same isn't true for, say, string operations, where there might be plenty of opportunity to move tight loops from Python to C and speed things up considerably.
- heavyset_go 6y agoTruthfully, I don't think optimization was a motivation for writing _count_elements() in Python or not. The CPython project doesn't prioritize optimization of the language or standard library unless there are clear performance gains to be made in the face of slow code. What most likely happened is someone wrote some code on a mailing list or bug report, and a maintainer included it as is. Reading the bug report that introduced Counter[1], the author states it is the simplest implementation they came up with, and Guido and other maintainers prioritized simplicity. [1] https://bugs.python.org/issue1696199 https://bugs.python.org/issue1696199
- MaxBarraclough 6y agoInteresting, thanks.