Python 'for' loop is memory inefficient

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sun Aug 16 21:28:40 EDT 2009


On 01:23 am, benjamin.kaplan at case.edu wrote:
>On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden <sturlamolden at yahoo.no> 
>wrote:
>>
>>A compiler could easily recognise a statement like
>>
>>  for i in range(n):
>>
>>as a simple integer loop. In fact, Cython is able to do this.
>
>but special cases aren't special enough to break the rules.

Although I think PyPy also recognizes this case and makes it as 
efficient as using xrange, and does so without breaking any rules.

There *are* _some_ legitimate complaints to be made about the CPython 
runtime. :)

Jean-Paul



More information about the Python-list mailing list