Why is this so much faster?

Tim Delaney timothy.c.delaney at gmail.com
Fri Jun 3 08:11:15 EDT 2011


On 3 June 2011 19:05, Thomas Jollans <t at jollybox.de> wrote:

>  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.
>

You are of course right ... that would be a d'oh! moment for me ;)

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110603/4bdcded4/attachment-0001.html>


More information about the Python-list mailing list