Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'amounts': 0.07; 'discard': 0.07; 'subject:file': 0.07; 'subject:two': 0.07; 'sys': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '2.7': 0.14; '100000000': 0.16; 'benjamin': 0.16; 'itertools': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'memory': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'task': 0.26; 'header:X-Complaints-To:1': 0.27; '(which': 0.31; 'follows': 0.31; 'running': 0.33; 'skip:# 10': 0.33; 'maybe': 0.34; 'subject:with': 0.35; 'but': 0.35; 'depends': 0.38; 'massive': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'break': 0.61; 'introduced': 0.61; 'real': 0.63; 'believe': 0.68; '(according': 0.84; 'manager).': 0.84; 'oscar': 0.84; 'subject:over': 0.84; 'items,': 0.91; 'imagine': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: iterating over a file with two pointers Date: Thu, 19 Sep 2013 16:38:08 +0200 Organization: None References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50848cf4.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379601478 news.xs4all.nl 15935 [2001:888:2000:d::a6]:51736 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54424 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()?