3 ms·
Is that still true in recent Python versions? Sounds like low-hanging fruit for perf optimisation.
by kristianp 4y ago
Is that still true in recent Python versions? Sounds like low-hanging fruit for perf optimisation.
- sgtnoodle 4y agoUsing exceptions in python isn't any more expensive than not using exceptions because the interpreter pays the same cost no matter what. It's a core design decision. Changing it would probably break some things.
- stevesimmons 4y agoPython 3.11 made the "try" part of exceptions zero-cost. The "except" part only has overhead if the exception is triggered.
- diarrhea 4y agoSo the answer to the question is yes, because for loops signal their finishing by raising an exception.
- tsimionescu 4y agoYes, the for loop still calls next() on the iterator until it throws a StopIteration exception.