Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'say,': 0.05; 'alain': 0.09; 'integers': 0.09; 'that).': 0.09; 'cc:addr:python-list': 0.11; 'creates': 0.14; 'ah,': 0.16; 'blocks': 0.16; 'calculates': 0.16; 'chunks.': 0.16; 'finds': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'regardless': 0.24; 'cc:2**0': 0.24; 'updating': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'bigger': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'object.': 0.31; 'writes:': 0.31; 'lists': 0.32; 'probably': 0.32; 'maybe': 0.34; 'subject:the': 0.34; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'pm,': 0.38; 'previous': 0.38; 'little': 0.38; 'explain': 0.39; 'does': 0.39; 'space': 0.40; 'even': 0.60; 'dave': 0.60; 'new': 0.61; 'profile': 0.61; "you'll": 0.62; 'size.': 0.65; 'due': 0.66; 'anything.': 0.68; 'behavior': 0.77; '2015': 0.84; 'overall,': 0.84; 'angel': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=LIcZtXXsvizFQ1XJK8R8QxtoDXNdu59nCMNwvwcAWTo=; b=koLDXmDDW/aIUo7sMGR94nPqXkyXRDxYtlesFDnc+jbNch/pScvkos4FH7sYNiU4op vyixXHSIMmgFL3R7MJfHwxIlWmhh+Tw1GWfz33+s1yvbtPFEfxVwf1UMHeSmJVj+nhVN kWO0FqDCgAyXnrSxUi4QRVCvPoNr9dl9i/OGrNUtA4hb1BqilXGEjHzpL13hG2Baq98w Zy50gVIn23nfVW3k/ElIXXVklg7Z7fxQGx+CIP+QaIZFxB2cxTIT37qqVZ6dmjVdW5mX igOh3w0+ouJBY54INl/wFJw195i2QWkRHof9zVleKsdBkH9nf5X22OEwQzuenqZsD8p4 kNcw== MIME-Version: 1.0 X-Received: by 10.42.43.199 with SMTP id y7mr2761611ice.12.1430991493749; Thu, 07 May 2015 02:38:13 -0700 (PDT) In-Reply-To: <87lhh0oikp.fsf@universite-de-strasbourg.fr.invalid> References: <87h9rvm576.fsf@Equus.decebal.nl> <55499304$0$12978$c3e8da3$5496439d@news.astraweb.com> <5549b41f$0$12927$c3e8da3$5496439d@news.astraweb.com> <8761853fkd.fsf@jester.gateway.sonic.net> <87pp6doh09.fsf@universite-de-strasbourg.fr.invalid> <87lhh0oikp.fsf@universite-de-strasbourg.fr.invalid> Date: Thu, 7 May 2015 19:38:13 +1000 Subject: Re: Throw the cat among the pigeons From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430991497 news.xs4all.nl 2969 [2001:888:2000:d::a6]:46389 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90093 On Thu, May 7, 2015 at 7:14 PM, Alain Ketterlin wrote: > Dave Angel writes: > >> On 05/06/2015 11:36 AM, Alain Ketterlin wrote: >>> Yes, plus the time for memory allocation. Since the code uses "r *= >>> ...", space is reallocated when the result doesn't fit. The new size is >>> probably proportional to the current (insufficient) size. This means >>> that overall, you'll need fewer reallocations, because allocations are >>> made in bigger chunks. >> >> That sounds plausible, but a=5; a*=4 does not update in place. It >> calculates and creates a new object. Updating lists can work as you >> say, but an int is immutable. > > Ah, okay. Even for big ints? If that is the case, my suggestion doesn't > explain anything. Anyway, with so many allocations for so little > arithmetic, the difference is probably due to the behavior of the > allocator (which maybe always finds blocks big enough, since one was > released after the previous multiplication, or something like that). The > only way to know would be to profile the VM. Yes, all integers are immutable. This is true regardless of the size of the integer, because: x = some_big_long_calculation() y = x y += 1 should never change the value of x. ChrisA