all() is slow?

Joshua Landau joshua.landau.ws at gmail.com
Mon Nov 7 17:51:21 EST 2011


See these all vs myAll tests:

%~> python all_test
0.5427970886230469
1.1579840183258057

3.3052260875701904
3.4992029666900635

3.303942918777466
1.7343430519104004

3.18320894241333
1.6191949844360352

In the first pair and the second pair, the pairs receive the same input.
The builtin all outperforms the user-defined.
In the second pair, the builtin receives a generator whereas the function
just runs. A generator has to be called once every iteration, and this
significantly slows it.

The main use of "all" is ease, though, as mentioned before.
The second is speed when testing lists/generators that don't need to be
wrapped.

Note:
%~> pypy all_test
0.0657250881195
0.0579369068146

0.751952171326
0.657609939575

0.748466968536
0.0586581230164

0.801791906357
0.0550608634949

If speed is your concern, there are simple solutions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111107/c8573884/attachment.html>


More information about the Python-list mailing list