Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:Python': 0.06; 'subject:string': 0.09; 'subject:question': 0.10; 'python': 0.11; '24,': 0.16; 'iterator': 0.16; 'objects.': 0.16; 'range.': 0.16; 'subject:handling': 0.16; 'subject:object': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'memory': 0.22; 'bytes': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'once,': 0.31; 'piece': 0.31; 'produces': 0.31; 'steven': 0.31; 'run': 0.32; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'list.': 0.37; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'range': 0.61; "you're": 0.61; 'needing': 0.65; 'size.': 0.65; 'here': 0.66; 'containing': 0.69; 'million': 0.74; '100': 0.79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=LMEhur9DirMNwP406zWOXNxoWeetsI6ztTBq70bnP/A=; b=fdk3o8fVhk11SFASE+2gdr0YfltCO7YPQ1ozgexluDtSs5FSrb2YLhXSWhf0k2nvux pbM9jvLuov/xK/eaCjqQZDVra4wcKPUjBbsXcqYSSWfc9coedqDq9v4w50jS6D/kpzRm HWKFOK/bGFJwnY92ksjWDRjBXxeBzgeu6hp/GzsFw51QUhRD+J24X14i4WqBQkPQ6pm/ djzFVl32idMrze80oPEWnDv4lcf4SF6RvHWo/u7FxwwqGU+unRwJjm0GwGe18fkFgDx/ qZw0gqkJLnLs/MiMT/bMWH9I1RTJ/4WpnqsOHW4GSG9kYPeSMR5cmqJSQl91aYxUY1j9 Q9ng== X-Received: by 10.70.91.142 with SMTP id ce14mr55274458pdb.138.1419439211828; Wed, 24 Dec 2014 08:40:11 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <549aa1f9$0$12981$c3e8da3$5496439d@news.astraweb.com> References: <549aa1f9$0$12981$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Wed, 24 Dec 2014 09:39:31 -0700 Subject: Re: question on string object handling in Python 2.7.8 To: Python Content-Type: multipart/alternative; boundary=001a11c2141e005dcf050af8f243 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1419439221 news.xs4all.nl 2934 [2001:888:2000:d::a6]:46848 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82899 --001a11c2141e005dcf050af8f243 Content-Type: text/plain; charset=UTF-8 On Wed, Dec 24, 2014 at 4:22 AM, Steven D'Aprano < steve+comp.lang.python@pearwood.info> wrote: > What happens here is that you time a piece of code to: > > - Build a large list containing 100 million individual int objects. Each int > object has to be allocated at run time, as does the list. Each int object > is about 12 bytes in size. Note to the OP: since you're using Python 2 you would do better to loop over an xrange object instead of a range. xrange produces an iterator over the desired range without needing to construct a single list containing all of them. They would all still need to be allocated, but not all at once, and memory could be reused. --001a11c2141e005dcf050af8f243 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Wed, Dec 24, 2014 at 4:22 AM, Steven D'Aprano <<= a href=3D"mailto:steve%2Bcomp.lang.python@pearwood.info">steve+comp.lang.py= thon@pearwood.info> wrote:
> What happens here is that you tim= e a piece of code to:
>
> - Build a large list containing 100 m= illion individual int objects. Each int
> object has to be allocated = at run time, as does the list. Each int object
> is about 12 bytes in= size.

Note to the OP: since you're using Python 2 you woul= d do better to loop over an xrange object instead of a range. xrange produc= es an iterator over the desired range without needing to construct a single= list containing all of them. They would all still need to be allocated, bu= t not all at once, and memory could be reused.
--001a11c2141e005dcf050af8f243--