Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12686

Re: List comprehension timing difference.

From Bart Kastermans <bkasterm@gmail.com>
Newsgroups comp.lang.python
Subject Re: List comprehension timing difference.
Date 2011-09-02 20:15 -0600
Organization MB-NET.NET for Open-News-Network e.V.
Message-ID <87bov29xsg.fsf@gmail.com> (permalink)
References <87zkinkcht.fsf@gmail.com> <mailman.676.1314925972.27778.python-list@python.org> <87sjofjbh1.fsf@gmail.com> <07906043-d732-43ca-8313-bee4746eca75@fi7g2000vbb.googlegroups.com>

Show all headers | View raw


ting@thsu.org writes:

> On Sep 2, 9:54 am, Bart Kastermans <bkast...@gmail.com> 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<b and d(a,b)==1:
>
> That way the d() function is called less than half the time. Of course
> this assumes that a<b is a faster evaluation than d(a,b), but I think
> that's true for your example.
> --
> // T.Hsu

Indeed makes quite a difference, goes from 275 seconds down to
153 seconds.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

List comprehension timing difference. Bart Kastermans <bkasterm@gmail.com> - 2011-09-01 18:35 -0600
  Re: List comprehension timing difference. MRAB <python@mrabarnett.plus.com> - 2011-09-02 02:12 +0100
    Re: List comprehension timing difference. Bart Kastermans <bkasterm@gmail.com> - 2011-09-02 07:54 -0600
      Re: List comprehension timing difference. ting@thsu.org - 2011-09-02 07:50 -0700
        Re: List comprehension timing difference. Bart Kastermans <bkasterm@gmail.com> - 2011-09-02 20:15 -0600

csiph-web