On Sun, Jun 7, 2009 at 3:34 PM, Emile van Sebille<[email protected]> wrote:
> To explain why we've tended to suggest using int and minval<val<maxval as > tests and avoid the range inclusion test, consider the following timeit > results: The performance penalty for 'in range(...)' is even greater when the value is not found, because the entire list must be searched: kent $ python -m timeit "0 <= 6000 <= 1000" 10000000 loops, best of 3: 0.111 usec per loop kent $ python -m timeit "6 in range(100)" 100000 loops, best of 3: 1.89 usec per loop kent $ python -m timeit "6000 in range(100)" 100000 loops, best of 3: 5.55 usec per loop kent $ python -m timeit "6 in range(1000)" 100000 loops, best of 3: 19 usec per loop kent $ python -m timeit "6000 in range(1000)" 10000 loops, best of 3: 55.4 usec per loop Kent _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
