all() is slow?
david vierra
codewarrior0 at gmail.com
Mon Nov 7 16:46:25 EST 2011
On Nov 7, 11:00 am, "OKB (not okblacke)"
<brenNOSPAMb... at NObrenSPAMbarn.net> wrote:
> What is the point of the all() function being a builtin if it's
> slower than writing a function to do the check myself?
>
But, you didn't write an all() function. You wrote a more specialized
allBoolean() function. I think this comparison is more fair to the
builtin all():
>>> def myAll(x):
... for a in x:
... if not a: return False
... return True
...
>>> timeit.timeit('myAll(a in (True, False) for a in x)', 'from __main__ import myAll, x', number=10)
14.510986388627998
>>> timeit.timeit('all(a in (True, False) for a in x)', 'from __main__ import x', number=10)
12.209779342432576
More information about the Python-list
mailing list