Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; '(even': 0.05; 'output': 0.05; '(b)': 0.07; 'assignment': 0.07; 'cache': 0.07; 'suppose': 0.07; 'variables': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variables.': 0.09; 'assignments': 0.16; 'lhs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rhs': 0.16; 'tuple': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'seems': 0.21; 'header:User-Agent:1': 0.23; '(a)': 0.24; 'connected': 0.24; 'mon,': 0.24; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(c)': 0.29; 'dec': 0.30; 'start,': 0.30; 'code': 0.31; 'end,': 0.31; 'subject:some': 0.31; 'tuples': 0.31; 'guess': 0.33; 'but': 0.35; 'method': 0.36; 'similar': 0.36; 'two': 0.37; 'performance': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'dave': 0.60; 'numbers': 0.61; 'simple': 0.61; 'more': 0.64; 'reads': 0.68; 'received:109': 0.72; 'faster.': 0.84; 'angel': 0.91; 'joel': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robin Becker Subject: Re: squeeze out some performance Date: Tue, 10 Dec 2013 12:54:13 +0000 References: <9df6ccd7-828d-43be-ac49-fe1c6a38bae7@googlegroups.com> <52A5E7BC.5090600@chamonix.reportlab.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 109.174.168.73 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386680060 news.xs4all.nl 2875 [2001:888:2000:d::a6]:35490 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61463 On 09/12/2013 20:46, Dave Angel wrote: > On Mon, 09 Dec 2013 15:54:36 +0000, Robin Becker wrote: >> On 06/12/2013 22:07, Joel Goldstick wrote: >> > end, start = start, end > >> a similar behaviour for simple assignments > >> for less than 4 variables the tuple method is faster. > > What does speed have to do with it? When you want to swap two variables, the > tuple assignment reads better. > Well the OP is asking about performance so I guess the look and feel might be sacrificed for speed in some circumstances. The tuple approach is more appealing when the lhs & rhs are connected, but it seems that even for more general assignments the tuple assignment may be faster for small numbers of variables. Looking at the output of dis for this case d,e,f=c,b,a it seems that we get code like this LOAD_NAME 3 (c) LOAD_NAME 2 (b) LOAD_NAME 1 (a) ROT_THREE ROT_TWO STORE_NAME 4 (d) STORE_NAME 5 (e) STORE_NAME 6 (f) for d = c e = b f = a we get this LOAD_NAME 3 (c) STORE_NAME 4 (d) LOAD_NAME 2 (b) STORE_NAME 5 (e) LOAD_NAME 1 (a) STORE_NAME 6 (f) which is not obviously slower, but I consistently get the former to be faster. I suppose it's a cache issue or something. However, for this particular case when the variables are not connected I find the tuple assignment less pythonic, but perhaps faster (even though in this case no tuples are built). -- Robin Becker