Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail From: Bart Kastermans Newsgroups: comp.lang.python Subject: Re: List comprehension timing difference. Date: Fri, 02 Sep 2011 20:15:11 -0600 Organization: MB-NET.NET for Open-News-Network e.V. Lines: 18 Message-ID: <87bov29xsg.fsf@gmail.com> References: <87zkinkcht.fsf@gmail.com> <87sjofjbh1.fsf@gmail.com> <07906043-d732-43ca-8313-bee4746eca75@fi7g2000vbb.googlegroups.com> NNTP-Posting-Host: kasterma.colorado.edu Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: gwaiyur.mb-net.net 1315016114 30314 128.138.150.65 (3 Sep 2011 02:15:14 GMT) X-Complaints-To: abuse@open-news-network.org NNTP-Posting-Date: Sat, 3 Sep 2011 02:15:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-User-ID: U2FsdGVkX19rSrLj2WlKYLkWHgP7GgFvoEV22pRNQc8m0WE70hazyfavLAUnPQL0 Cancel-Lock: sha1:qboNUeJz6cXAexVFQJ9c7bq3t3s= sha1:g7BCdPgRjuymeGfGz+UybOCfgAg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12686 ting@thsu.org writes: > On Sep 2, 9:54 am, Bart Kastermans wrote: >> if d(a,b) == 1 and a < b: > > It will probably be faster if you reverse the evaluation order of that > expression. > > if a > That way the d() function is called less than half the time. Of course > this assumes that a that's true for your example. > -- > // T.Hsu Indeed makes quite a difference, goes from 275 seconds down to 153 seconds.