Array of 2^n

Chris Barker chrishbarker at home.net
Tue Oct 23 12:22:05 EDT 2001


Skip Montanaro wrote:
> 
>     Andreas> Well, at least for python 2.0 (SuSE 7.2) this way [list
>     Andreas> comprehensions] is also about 25% slower than map/lambda...
>     Andreas> Has it been sped up in later versions?
> 
> Not significantly.  List comprehensions are byte compiled to almost the same
> code that you would get with the obvious for loop translation.  Map(), on
> the other hand, is a function, so it gets compiled to a function call
> opcode.  That means the loop machinery runs in C instead of in the Python
> virtual machine.

We had a fairly long discussion about this here a month or so ago, and
I, for one, am sad about this fact. I understand that compiling a list
comprehension to a set of for loops is easy to do and easy to explain,
but it unfortunately makes it impossible to later re-wriote the
internals to get the perfomance advantages of map(), without potentially
breaking code. The difference is that both the expression and the input
lists can be altered in the middle of the looping.

We never did get an answer to the question of whether the full
dynamisicm of for loops being allowed in list comprehensions was a
design decision or the result of an implimentation decision, but I
suppose it's too late now to change it anyway. It would make me feel
better if I knew that Guido et al. thought it was an important attribute
of the design.

-Chris

> The Python disassembler is instructive here, and so simple to use, everyone
> ought to be familiar with it, even if just to answer these sorts of
> questions.

Cool. Thanks for the tutorial.

-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