Re: range() is not the best way to check range?
- From: "Dan Bishop" <danb_83@xxxxxxxxx>
- Date: 17 Jul 2006 20:09:00 -0700
Leif K-Brooks wrote:
Summercoolness@xxxxxxxxx wrote:
or is there an alternative use of range() or something similar that can
be as fast?
You could use xrange:
leif@ubuntu:~$ python -m timeit -n10000 "1 in range(10000)"
10000 loops, best of 3: 260 usec per loop
leif@ubuntu:~$ python -m timeit -n10000 "1 in xrange(10000)"
10000 loops, best of 3: 0.664 usec per loop
That's only because you're choosing a number that's early in the list.
~$ python -m timeit -n10000 "1 in xrange(10000)"
10000 loops, best of 3: 1.22 usec per loop
~$ python -m timeit -n10000 "9999 in xrange(10000)"
10000 loops, best of 3: 1.24 msec per loop
That's *milliseconds*, not microseconds.
.
- References:
- range() is not the best way to check range?
- From: Summercoolness
- Re: range() is not the best way to check range?
- From: Leif K-Brooks
- range() is not the best way to check range?
- Prev by Date: Re: question about what lamda does
- Next by Date: Re: range() is not the best way to check range?
- Previous by thread: Re: range() is not the best way to check range?
- Next by thread: Re: range() is not the best way to check range?
- Index(es):
Relevant Pages
|