Even getting all the prime numbers less than 1000, the Sieve method is roughly 3 times faster than the method shown above. I would expect its advantage to grow as the number of prime numbers desired grows.
EDIT: I couldn't stand it; had to test my gut feelings.
Yes, if you ask for all prime numbers less than 5000, then the Sieve outperforms the modulo by a factor of *TEN*.
Not surprising, but I just wanted to check my sanity.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Last edited by Old Pedant; 06-26-2013 at 05:52 AM..