Skip to main content

Timeline for Prime Number Speed

Current License: CC BY-SA 3.0

6 events
when toggle format what by license comment
Jun 10, 2014 at 20:51 comment added user39138 I think the other answer is essentially the same algorithm as yours, with some implementation differences. For example, he initializes the list to a capacity that is an estimate of the number of primes there will be. That saves a little time by avoiding List grows. You could do something similar by just initializing like this: Primes = new List<int>(Math.Min(1000,(count+1)/2)). That can shave a couple percent more from your time. Most list grows are on the low end (4, 8, 16, 32, ...). Using a floating point equation to estimate the capacity can consume a lot of the time you're hoping to save.
Jun 10, 2014 at 19:58 comment added John Davis From what I read, the Sieve of Atkin employs wheel-factorization, however I still can't understand the other answer is any different form mine.
Jun 10, 2014 at 19:54 history edited user39138 CC BY-SA 3.0
added 144 characters in body
Jun 10, 2014 at 19:49 comment added user39138 I haven't played with the Sieve of Atkin, so I can't speak to speed comparisons to it.
Jun 10, 2014 at 19:34 comment added John Davis I fixed the "past bound" problem (see my comment on my post). This is exactly the thing that I'm looking for - the reason my code was slower. My results are the same as yours - however your modified code (and now my modified code) beats the Sieve of Atkin. Is this because the Atkin code provided is not optimized?
Jun 10, 2014 at 19:15 history answered user39138 CC BY-SA 3.0