On Tue, 19 Jan 2016 09:24 pm, Oscar Benjamin wrote:

> On 19 Jan 2016 10:16, "Steven D'Aprano" <st...@pearwood.info> wrote:
>>
>> [steve@ando ~]$ python -m timeit -s "from collections import deque"
>>     -s "it = iter([i for i in xrange(1000)])" "deque(it, maxlen=0)"
>> 1000000 loops, best of 3: 0.913 usec per loop
>>
>>
>> [steve@ando ~]$ python -m timeit -s "from collections import deque"
>>     -s "it = (i for i in xrange(1000))" "deque(it, maxlen=0)"
>> 1000000 loops, best of 3: 0.965 usec per loop
> 
> Surely the iterator in the above benchmarks is consumed during the first
> of 1000000 loops. Subsequent loops are just calling next on an exhausted
> iterator.

You know, I think you're right. Damn.

I keep getting bitten by that aspects of iterators and timeit.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to