Confusing performance results for prime

Greg Brunet gregbrunet at NOSPAMsempersoft.com
Sat Oct 18 20:08:35 EDT 2003


"Lulu of the Lotus-Eaters" <mertz at gnosis.cx> wrote in message
news:mailman.188.1066456959.2192.python-list at python.org...
> bokr at oz.net (Bengt Richter) wrote previously:
> |In doing some testing of different but simple algorithms for getting
a
> |list of prime numbers
>
> This general topic came up quite recently.  I myself wrote a bunch
about
> various data structures to cache primes and the like.  But that was
all
> fairly idle.
>
> If you want to test primality quickly, using the sieve of erotosthenes
> is pretty terrible.  At least if you only want to check relatively few
> numbers, rather than assemble all the primes.  Orders of magnitude
> better is to use Miller-Rabin pseudoprimality tests (well, complexity
> orders really).
>
> Pick the right algorithm before worrying about micro-optimizations.

Well, actually I was trying to get the list of primes (as well as a
count of them) below a specified value - so perhaps the sieve is the
better algorithm to use.  I also was just testing simple, easy to
understand algorithms.  Finally, the question was really more about
understanding the cause of the behavior I was seeing after making the
changes.  I think that has been acheived.  Thanks,


-- 
Greg





More information about the Python-list mailing list