Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'anyway': 0.03; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; '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; 'subject:" ': 0.10; 'addition.': 0.16; 'reedy': 0.16; 'subject:=': 0.16; 'versus': 0.16; 'wrote:': 0.16; 'language': 0.17; 'once,': 0.18; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'variable': 0.24; 'module': 0.30; 'there': 0.33; 'to:addr:python- list': 0.33; 'wondering': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'fastest': 0.37; 'using': 0.37; 'but': 0.37; 'received:org': 0.38; 'easier': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'subject: (': 0.39; "it's": 0.40; 'more': 0.60; 'subject:+': 0.73; 'difference.': 0.84; 'percent.': 0.84; 'readability': 0.84; 'prone': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") Date: Sun, 21 Aug 2011 22:15:07 -0400 References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.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-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313979609 news.xs4all.nl 23936 [2001:888:2000:d::a6]:55570 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11987 On 8/21/2011 7:49 PM, Laurent Payot wrote: > I made Python my language of choice because of its readability and > simpleness, and not because of its speed. But it's always good to > know what is the fastest sometimes when you don't want to write a > module in C. So I was just wondering if there was a difference. There > is, of a few percent. Anyway I will keep on using the 2% slower "i += > 1" because for me that's less prone to errors because you write the > variable only once, and that's more important than speed. For longer variable names, it is also easier and faster to read once one gets used to the idiom. number_of_chars += 1 # versus number_of_chars = number_of_chars + 1 Not repeating was a major reason for the addition. -- Terry Jan Reedy