3 ms·
Why is truth() faster than bool() in Python?
- pwf 13y agoFor those wondering what the hell truth() is, I think they're talking about this phenomenon: python -m timeit "if bool(1): x = 1" 1000000 loops, best of 3: 0.187 usec per loop python -m timeit "if 1: x = 1" 10000000 loops, best of 3: 0.0266 usec per loop
- nemetroid 13y agotruth() is a function defined in the operator module which does kind of the same thing as bool().
- dhugiaskmak 13y agoThis article doesn't actually answer the question posed by the title, FYI.
- nemetroid 13y agoUncommon to see such a linkbaitish title for a programming post. The reason truth() (from operator) is faster than bool() is that * bool() takes one optional and named argument, and * truth() takes one argument.