On Feb 10, 7:29 am, Stefan Behnel <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > On Sat, 09 Feb 2008 01:11:09 +0000, Marc 'BlackJack' Rintsch wrote: > > >> On Fri, 08 Feb 2008 05:12:29 -0800, Ryszard Szopa wrote: > > >>> Expressing simple loops as C for loops... > >> You mean simple loops like ``for i in xrange(1000):``? How should the > >> compiler know what object is bound to the name `xrange` when that loop > >> is executed? > > > Assuming the aim is to optimize for speed rather than memory, the > > solution is for the compiler to create something like this pseudo-code: > > > if xrange is Python's built-in xrange: > > execute optimized for-loop at C-like speed > > else: > > execute unoptimized normal loop at Python speed > > > (In case it's not obvious, the decision of which branch to take is made > > at run time, not compile time.) > > > I understand that is more or less what psycho already does. > > ... and Cython, when iterating over lists, for example. That's one of the > reasons why looping is so much faster in Cython than in Pyrex. > > Stefan- Hide quoted text - > > - Show quoted text -
There's always the Visitor pattern. in xrange(10000).for x: loop_of_x_at_forlike_speed() Do identifiers get hashed once at compile/ definition-execution time, or every time they're encountered? This could be fast... -- http://mail.python.org/mailman/listinfo/python-list