I've implemented a basic sieve to see if it does any better than trial division.
While trial division found the first million primes in 8.28 seconds the sieve does the same task in 0.84 seconds. That's a little better!
Running the sieve on the range [2..1,000,000,002) yields 50,847,534 primes in 78.14 seconds. I'm currently storing a byte for each number so that means I'm using 1GB ram. We can't just keep increasing the range because we will eventually run out of memory. Even storing a single bit for each number (we only need to know if it has been crossed our or not) would only divide this by a factor of 8.
Perhaps we can work on a section of the number line at a time?
While trial division found the first million primes in 8.28 seconds the sieve does the same task in 0.84 seconds. That's a little better!
Running the sieve on the range [2..1,000,000,002) yields 50,847,534 primes in 78.14 seconds. I'm currently storing a byte for each number so that means I'm using 1GB ram. We can't just keep increasing the range because we will eventually run out of memory. Even storing a single bit for each number (we only need to know if it has been crossed our or not) would only divide this by a factor of 8.
Perhaps we can work on a section of the number line at a time?
Comments
Post a Comment