Python is faster than C

Hallvard B Furuseth (nospam nospam) h.b.furuseth at usit.uio.no
Sat Apr 3 19:05:32 EST 2004


Armin Rigo wrote:

>> Forcing enumerate to return a list would drag not only the entire
>> 40GB.csv into memory, but also the entire set of i. Using an iterator
>> in this case instead of a list *is* the optimization.
> 
> Yes, and I'm ranting against the idea that the programmer should be
> bothered about it, when it could be as efficient automatically.  From
> the programmer's perspective, iterators are mostly like a sequence
> that you can only access once and in order.  A better implementation
> can figure out for itself when you are only accessing this sequence
> once and in order.

It seems bad to me to teach programmers to depend on such optimizations
happening automatically.  Then people will sometimes depend on an
optimization at a time Python does not perform it, and the program will
unexpectedly try to consume 4G memory or whatever.  In particular if too
many such optimizations are added, so programmers lose track of which
optimizations are performed when.  Debugging such a problem will be no
fun either, for the same reason.

By all means use the same types and language constructs that already
exist instead of heaping on new ones, but add a way to say 'optimize
this!' and raise an exception if the construct is used in a way which
prevents the optimization.

-- 
Hallvard



More information about the Python-list mailing list