Speed-up for loops

Ulrich Eckhardt eckhardt at satorlaser.com
Fri Sep 3 08:52:07 CEST 2010


Tim Wintle wrote:
> [..] under the hood, cpython does something like this (in psudo-code)
> 
> itterator = xrange(imax)
> while 1:
>   next_attribute = itterator.next
>   try:
>     i = next_attribute()
>   except:
>     break
>   a = a + 10

There is one thing that strikes me here: The code claims that each iteration
there is a lookup of the 'next' field in the iterator. I would expect that
this is looked up once before the loop only.

Can you confirm that or am I misinterpreting your intention here?

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list