Loop performance disappearance

Tim Peters tim_one at email.msn.com
Thu Mar 16 02:19:22 CET 2000

[Chris Ryland]
> I always assumed (perhaps being too much of a newbie) that
> for i in range(n):
>    :
> would automatically be recognized by the compiler and turned into a simple
> loop control using i alone (like turning it into an xrange, I guess).
> ...

CPython is currently about as WYSIWYG as languages come.

Total number of lines of Python compiler code devoted to optimization:  a
couple dozen, all related to speeding local vrbl access.

Total number of hours Python users have spent tracking down Python compiler
optimization bugs:  0.

Total number of hours Python users have spent tracking down optimization
bugs in the C compilers they use to compile Python:  impossible to say, but
thousands is a conservative lower bound.

In time, you'll learn to write Python that's pretty quick.  That the
language does exactly what you tell it to do is a great aid in this (e.g.,
"range" always returns a list, "xrange" never does -- does anyone really
need more info than that to know what to write next <wink>?).

    y'rs  - tim, who used to make his living writing optimizing compilers,
                 and finds Python a great relief <0.5 wink>.

More information about the Python-list mailing list