in reply to RE: RE: RE: sieve of erothenes
in thread sieve of erothenes
Hadn't even thought about benchmarking them...
I suspect that it isn't my looping structure, but that I'm stepping across the primes low to high and you're going high to low. My code tests division by '2' first, so the inner loop only runs once half of the time. Thus only runs twice a third of the time, 4 times a fifth of the time, etc.
since you test the large numbers first, you have to make more tests to throw out a potential prime.
consider your test of 16:
16%13 -> 16%11 -> 16%7 -> 16%5 -> 16%3 -> 16%2 (not prime)
as opposed to mine:
16%2 (not prime)
The foreach may have temp array overhead, but it looks like I'm making up for it on number of % and iterations
/\/\averick
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: RE: RE: RE: sieve of erothenes
by husker (Chaplain) on Jul 05, 2000 at 18:05 UTC | |
RE: RE: RE: RE: RE: sieve of erothenes
by Adam (Vicar) on Jul 01, 2000 at 22:12 UTC |
In Section
Cool Uses for Perl