Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82899

Re: question on string object handling in Python 2.7.8

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 <ian.g.kelly@gmail.com>
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; '&gt;': 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 <mailman.17176.1419410409.18130.python-list@python.org> <549aa1f9$0$12981$c3e8da3$5496439d@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 24 Dec 2014 09:39:31 -0700
Subject Re: question on string object handling in Python 2.7.8
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17187.1419439221.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

question on string object handling in Python 2.7.8 Dave Tian <dave.jing.tian@gmail.com> - 2014-12-23 20:28 -0500
  Re: question on string object handling in Python 2.7.8 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-24 22:22 +1100
    Re: question on string object handling in Python 2.7.8 Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-24 09:39 -0700
  Re: question on string object handling in Python 2.7.8 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-25 17:23 +1300
  Re: question on string object handling in Python 2.7.8 Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-25 16:34 +0000

csiph-web