Performance of list comprehensions vs. map

Chris Barker chrishbarker at home.net
Mon Sep 10 14:37:07 EDT 2001


"Delaney, Timothy" wrote:

> Yep - now you know why so many people have *not* put the effort into
> optimising Python. Dynamism pervades almost every part of the language.
> 
> The only optimisations I've seen proposed in recent times which truly look
> interesting are
> 
> PEP 266: Optimizing Global Variable/Attribute Access
> http://python.sourceforge.net/peps/pep-0266.html
> 
> PEP 267: Optimized Access to Module Namespaces
> http://python.sourceforge.net/peps/pep-0267.html
> 
> both of which need implementing and testing to determine (a) whether they
> are indeed an improvement, and (b) whether they are enough of an improvement
> when balanced by how much they complicate the Python core code.

These both do look good, but let's face it: It's not even clear that
they will help at all, and certainly not enough to make a huge
difference.

My issue with the dynamicism of Python is that it is wonderful and
powerful, but frankly, not used in a great deal of code: How amny people
even new that you could change the code of a function on the fly, let
alone actually used the feature? And of those few that have used the
feature, how often have they used it?

What I am searching for in this discussion are ways that Python can take
advantage of the fact that much code is not, in fact, all that dynamic.
I suspect that most of the time that a list comprehension or map is
called, the author of the code fully expects the expression (or
function) to do the same thing for the duration of the call, and that
the sequence is more often than not homogenous. There must be some way
to take advantage of that circumstance. Granted, we could speed up map
and list comprehensions a whole lot, and that wouldn't speed up the
language as a whole all that much, but this is just an example.

Perhaps the only way to do it would be to sprinkle a few "static" or
something statements in. Frankly I think this is ugly, but the current
answer to a few core functions in a Python program being too slow is to
re-code it in C. Surely that is ugly!


I-know-there-are-no-easy-answers-but-I-wish-there-were-ly yours,

-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