Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89607
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Lucky numbers in Python |
| Organization | Decebal Computing |
| References | (1 earlier) <mailman.95.1430337506.3680.python-list@python.org> <87d22mbod7.fsf@Equus.decebal.nl> <mailman.103.1430347166.3680.python-list@python.org> <871tj2bi2p.fsf@Equus.decebal.nl> <mailman.110.1430362572.3680.python-list@python.org> |
| Date | 2015-04-30 08:34 +0200 |
| Message-ID | <87r3r29lal.fsf@Equus.decebal.nl> (permalink) |
Op Thursday 30 Apr 2015 04:55 CEST schreef Ian Kelly: > On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof <Cecil@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 20:24 +0200
Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 13:57 -0600
Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 23:45 +0200
Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 16:38 -0600
Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 02:01 +0200
Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 20:55 -0600
Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 08:34 +0200
Re: Lucky numbers in Python Chris Kaynor <ckaynor@zindagigames.com> - 2015-04-29 15:56 -0700
Re: Lucky numbers in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 10:11 +1000
Re: Lucky numbers in Python Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-29 21:08 -0600
Re: Lucky numbers in Python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 20:55 +0200
Re: Lucky numbers in Python Dave Angel <davea@davea.name> - 2015-04-30 15:28 -0400
csiph-web