Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101899
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Why generators take long time? |
| Date | 2016-01-19 10:24 +0000 |
| Message-ID | <mailman.105.1453199051.15297.python-list@python.org> (permalink) |
| References | <1e092318-5052-4383-aabe-dd979d72645d@googlegroups.com> <569e0beb$0$1621$c3e8da3$5496439d@news.astraweb.com> |
On 19 Jan 2016 10:16, "Steven D'Aprano" <steve@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. -- Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why generators take long time? Arshpreet Singh <arsh840@gmail.com> - 2016-01-18 23:27 -0800
Re: Why generators take long time? Arshpreet Singh <arsh840@gmail.com> - 2016-01-19 00:06 -0800
Re: Why generators take long time? Steven D'Aprano <steve@pearwood.info> - 2016-01-19 21:11 +1100
Re: Why generators take long time? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-01-19 10:24 +0000
Re: Why generators take long time? Steven D'Aprano <steve@pearwood.info> - 2016-01-20 10:58 +1100
Re: Why generators take long time? Arshpreet Singh <arsh840@gmail.com> - 2016-01-19 11:35 -0800
Re: Why generators take long time? Jason Swails <jason.swails@gmail.com> - 2016-01-19 15:19 -0500
Re: Why generators take long time? Jason Swails <jason.swails@gmail.com> - 2016-01-19 15:25 -0500
csiph-web