Performance of list comprehensions vs. map

Chris Barker chrishbarker at home.net
Mon Sep 10 14:26:44 EDT 2001


Skip Montanaro wrote:
>     Tim> Yep - now you know why so many people have *not* put the effort
>     Tim> into optimising Python. Dynamism pervades almost every part of the
>     Tim> language.
> 
> I don't see how substituting one code object for another makes optimizing a
> function any harder or easier.

I'm not sure he was neccessarily referring to that particular example,
but I do think he's right:

Let's say that my homogenous sequence proposal were in place, and you
had the line of code:

map(func,sequence)

A mythical JIT compiler could compile a version of func that worked on
the type of object in sequence, and then apply it to all the elements.
Onoce all the checking and compiling was done, that would run as fast as
a static,compiled language, and therefore give a major speed-up (if
sequence was long enough). However, since the code object in func could
be changed while the map loop was running, there would have to be a
check to make sure both the code and the sequence had not changed. This
would ensure that the innner loop could NEVER be as fast as compiled
static code.

Anyone know how LISP deals with this: it is certainly a very dynamic
language.

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list