Op Thursday 30 Apr 2015 04:55 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof <ce...@decebal.nl> wrote: >> Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: >>> In that case you can definitely omit the middle term of the slice, >>> which will be both more concise and clearer in intent, though >>> probably not significantly faster. >> >> It is certainly nit faster. It is even significantly slower. With >> the middle term lucky_numbers(int(1e6)) takes 0.13 seconds. Without >> it takes 14.3 seconds. Hundred times as long. > > That would be rather surprising, since it's the same operation being > performed, so I did my own timing and came up with 0.25 seconds > (best of 3) with the middle term and 0.22 seconds without. > > I suspect that you tested it as "del sieve[skip_count - 1 : > skip_count]" (which would delete only one item) rather than "del > sieve[skip_count - 1 :: skip_count]".
Yeah, that is how I interpreted omitting the middle term. But it seemed to give the right results. With your amendment it runs slightly faster. With 1E7 it is 8.0 and 7.7. So almost 4% faster. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list