Loop performance disappearance

Bernhard Herzog herzog at online.de
Thu Mar 16 13:26:00 EST 2000


"Chris Ryland" <cpr at emsoftware.com> writes:

> Several people kindly pointed out that it's hard in Python, because the
> definition of "range" might be anything.
> 
> I guess xrange is an OK compromise, but this points up the need (observed in
> other threads recently) for some kind of optimizing compiler that will take
> a whole project, do dataflow and definitional analysis on it, perhaps take
> your word for it that you're not replacing any of the built-in functions or
> classes in an exec/eval, and do some serious optimizations along these
> lines.

This particular case could be optimized if the special syntax for list
construction based on slice-notation is adopted. [start:stop] would be
equivalent to range(start, stop) and [start:stop:step] equivalent to
range(start, stop, step). So you'd write

   for x in [0:100]:
	print x

This will, conceptually at least, always iterate over a new list of
integers and that opens the door to potential optimizations.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list