Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54424
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: iterating over a file with two pointers |
| Date | 2013-09-19 16:38 +0200 |
| Organization | None |
| References | (3 earlier) <roy-B13238.08561818092013@news.panix.com> <CAHVvXxQa6rsrD669kL-EeqCQFn3jKH-k=eWY5iey4RwVBD2RiA@mail.gmail.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> <l1e8ol$99q$1@ger.gmane.org> <CAHVvXxQXqvKr5eoxGmYgbQMPt-N6eZRT50EBOjOuVYu_DbCQMQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.150.1379601478.18130.python-list@python.org> (permalink) |
Oscar Benjamin wrote: > $ cat tee.py > #!/usr/bin/env python > > import sys > from itertools import tee > > items = iter(range(int(sys.argv[1]))) > > while True: > for x in items: > items, discard = tee(items) > break > else: > break > > print(x) > > $ time py -3.3 ./tee.py 100000000 > 99999999 > > real 1m47.711s > user 0m0.015s > sys 0m0.000s > > While running the above python.exe was using 6MB of memory (according > to Task Manager). I believe this is because tee() works as follows > (which I made up but it's how I imagine it). [...] > However, when I ran the above script on Python 2.7 it did consume > massive amounts of memory (1.6GB) and ran slower so maybe this depends > on optimisations that were introduced in 3.x. Did you use xrange()?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
iterating over a file with two pointers nikhil Pandey <nikhilpandey90@gmail.com> - 2013-09-18 04:12 -0700
Re: iterating over a file with two pointers Chris Angelico <rosuav@gmail.com> - 2013-09-18 21:21 +1000
Re: iterating over a file with two pointers nikhil Pandey <nikhilpandey90@gmail.com> - 2013-09-18 05:07 -0700
Re: iterating over a file with two pointers Travis Griggs <travisgriggs@gmail.com> - 2013-09-18 09:18 -0700
Re: iterating over a file with two pointers Dave Angel <davea@davea.name> - 2013-09-18 11:39 +0000
Re: iterating over a file with two pointers Roy Smith <roy@panix.com> - 2013-09-18 08:56 -0400
Re: iterating over a file with two pointers Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-18 14:09 +0100
Re: iterating over a file with two pointers Roy Smith <roy@panix.com> - 2013-09-18 10:36 -0400
Re: iterating over a file with two pointers Dave Angel <davea@davea.name> - 2013-09-18 20:07 +0000
Re: iterating over a file with two pointers Peter Otten <__peter__@web.de> - 2013-09-19 09:23 +0200
Re: iterating over a file with two pointers Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-19 15:16 +0100
Re: iterating over a file with two pointers Peter Otten <__peter__@web.de> - 2013-09-19 16:38 +0200
Re: iterating over a file with two pointers Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-19 15:48 +0100
Re: iterating over a file with two pointers Peter Otten <__peter__@web.de> - 2013-09-18 13:44 +0200
Re: iterating over a file with two pointers nikhil Pandey <nikhilpandey90@gmail.com> - 2013-09-18 05:14 -0700
Re: iterating over a file with two pointers Peter Otten <__peter__@web.de> - 2013-09-18 14:54 +0200
Re: iterating over a file with two pointers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-19 02:40 +0000
Re: iterating over a file with two pointers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-19 02:56 +0000
Re: iterating over a file with two pointers Joshua Landau <joshua@landau.ws> - 2013-09-19 08:04 +0100
csiph-web