Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'assignment': 0.07; 'modified': 0.07; 'assigning': 0.09; 'augmented': 0.09; 'calculating': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'similar,': 0.09; 'target,': 0.09; 'jan': 0.12; '"an': 0.16; 'effect.': 0.16; 'evaluating': 0.16; 'in-place': 0.16; 'in- place,': 0.16; 'nope,': 0.16; 'once.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'rewritten': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'possible,': 0.19; 'meant': 0.20; 'manual': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'nearly': 0.26; 'possibly': 0.26; 'world,': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'ideal': 0.29; 'statement': 0.30; "skip:' 10": 0.31; 'fast.': 0.31; 'says': 0.33; 'actual': 0.34; 'except': 0.35; 'equal': 0.35; 'johnson': 0.35; 'but': 0.35; 'should': 0.36; 'two': 0.37; 'version,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'ian': 0.60; 'new': 0.61; 'received:173': 0.61; 'more': 0.64; "'similar'": 0.84; 'received:fios.verizon.net': 0.84; 'same,': 0.91; 'rick': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Tuples and immutability Date: Tue, 11 Mar 2014 23:25:19 -0400 References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394594751 news.xs4all.nl 2829 [2001:888:2000:d::a6]:38371 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68258 On 3/11/2014 10:01 PM, Rick Johnson wrote: > > On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >> x += y is meant to be equivalent, except possibly in-place and >> more efficient, than x = x + y. The manual actually says "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect. In the augmented version, x is only evaluated once. Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead. > In an ideal world, the speed of these two codes should be the same, Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once and possibly allocating a new object versus not take extra time. In a statement like "x.y.z[3*n+m] += 1", calculating the target dominates the time to increment, so this form should be nearly twice as fast. -- Terry Jan Reedy