Why is this so much faster?

Thomas Jollans t at jollybox.de
Fri Jun 3 05:05:12 EDT 2011


On Friday 03 June 2011, it occurred to Tim Delaney to exclaim:
> Probably the biggest savings are list creating and jumping between C- and
> Python-functions during the map call. The lambda is a Python function,
> which are notoriously slow to use from within map() in comparison to
> keeping it all as C-level. Creating intermediate lists is totally
> unnecessary and obviously a waste of time. You're actually creating 3
> intermediate lists - one with map(), one with zip() and one with range()
> (the third only if this is Python 2.x code, not 3.x).

Actually, in Python 3, map and zip also return iterators, so I would expect 
the two versions to be almost the same speed in Python 3. The Python function 
call is of course still slow.

-TJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110603/6b3e8ad7/attachment-0001.html>


More information about the Python-list mailing list