Generators/iterators, Pythonicity, and primes

Arnaud Delobelle arnodel at googlemail.com
Sun Apr 12 15:29:31 CEST 2009


Duncan Booth <duncan.booth at invalid.invalid> writes:

> John Posner <jjposner at snet.net> wrote:
>
>> Do know what in the itertools implementation causes adding a 'if p <=
>> sqrt(n)' clause to *decrease* performance, while adding a
>> 'takewhile()' clause *increases* performance? 
>
> I haven't timed it, but I would guess that the takewhile was faster 
> only because the sqrt(n) had been factored out of the loop. Try the 
> original loop again precalculating the sqrt(n) and see how that compares.

Most likely

-- 
Arnaud



More information about the Python-list mailing list