all() is slow?

Chris Rebert clp2 at rebertia.com
Mon Nov 7 16:39:57 EST 2011


On Mon, Nov 7, 2011 at 1:00 PM, OKB (not okblacke)
<brenNOSPAMbarn at nobrenspambarn.net> wrote:
<snip>
>        What is the point of the all() function being a builtin if it's
> slower than writing a function to do the check myself?

Regardless of whether it's slower (which I expect someone will be
along to debunk or explain shortly), do you really want to have to
write an additional boilerplate function or block of code /every
single time/ you want to do such a check? The runtime speed difference
is unlikely to be worth your time as a developer in many cases. And by
Murphy's Law, you *will* make errors writing these repetitive code
blocks (e.g. forget to negate the conditional), whereas reusing all()
makes that much less likely.

The trade-off is run-time speed for developer
productivity/convenience; Python tends to lean towards the latter (to
varying degrees).

Cheers,
Chris



More information about the Python-list mailing list