while (a=b()) ... (transmogrified to a range thread)

Jeremy Hylton jeremy at cnri.reston.va.us
Wed May 19 14:31:45 EDT 1999


>>>>> "TP" == Tim Peters <tim_one at email.msn.com> writes:

  TP> [Jeremy Hylton]
    > ...
    > Right.  I was timing an iteration over the range --
    >     for i in xrange(N): pass
    > vs.
    >     for i in range(N): pass
    > In this case, range nearly always wins -- even for N == 1000000.

  TP> ...
  TP> Devious experiment: try swapping the order of those two lines
  TP> and see whether range still wins.

Actually, I was being devious from the start.  I did the tests in the
reverse of the order I described them above.  I re-reversed them and
still see the same results -- range faster than xrange.

Repeated the tests on a Pentium Pro box running Solaris x86, and I do
see the results you lead me to expect.  Somewhere between N=10000 and
N=100000, xrange becomes faster than range.  For N<10000, range is
faster, but only a little faster.

Jeremy




More information about the Python-list mailing list