Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Prime list

by danaj (Friar)
on Feb 12, 2015 at 17:19 UTC ( [id://1116528] : note . print w/replies, xml ) Need Help??


in reply to Re: Prime list
in thread Prime list

I would suggest actually looking at a sieve, for example the ones on RosettaCode. They are much faster than the trial division method you link to, albeit generating primes starting at two.

For doing trial division, the skip-2-3 primality test from RosettaCode is twice as fast as the code you link to. Just wrap in something like: my @primes = grep { isprime($_) }  1..1000000;

While the regex solution mentioned in another reply is super clever, it is also super not useful for the task once past toy sizes.