Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tests,': 0.07; 'python': 0.08; 'processor,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'slowest': 0.09; 'subject:" ': 0.10; '3.2.1': 0.16; 'amd': 0.16; 'received:173.11': 0.16; 'resist': 0.16; 'subject:=': 0.16; 'header:In-Reply-To:1': 0.22; '64-bit': 0.23; 'windows': 0.26; 'loop': 0.28; '(so': 0.30; 'ran': 0.30; 'to:addr:python-list': 0.33; '...': 0.34; 'header:User- Agent:1': 0.34; 'richard': 0.34; 'corp.': 0.34; 'header:X -Complaints-To:1': 0.35; 'fastest': 0.37; 'machine': 0.37; 'using': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header :Mime-Version:1': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'subject: (': 0.39; 'copyright': 0.62; 'subject:+': 0.73; '2.60': 0.84; '620': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Emile van Sebille Subject: Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") Date: Mon, 22 Aug 2011 09:35:56 -0700 References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 173-11-108-137-sfba.hfc.comcastbusiness.net User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314030982 news.xs4all.nl 23961 [2001:888:2000:d::a6]:59559 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12039 On 8/22/2011 2:55 AM Richard D. Moores said... > I couldn't resist giving it a try. Using Python 3.2.1 on a 64-bit > Windows 7 machine with a 2.60 gigahertz AMD Athlon II X4 620 > processor, I did 18 tests, alternating between n=n+1 and n+=1 (so 9 > each). > > The fastest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0879 usec per loop > > The slowest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0902 usec per loop > > The fastest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0831 usec per loop > > The slowest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0842 usec per loop > > Coincidence? > Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :) Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile>