Closed t-w closed 1 year ago
OK. I see. That algorithm does indeed something a bit different than it seemed at first glance - it does not store information about primes it finds (what could be easily added, eg in a second array), it just counts them, using the array in a more packed way.
Interesting, thanks for checking.
If I understand correctly what the
sieve.pas
benchmarks tests are supposed to do (count primes up to a certain number, 8192 in the tests) - the algorithm used to calculate primes:is not correct - it counts 1899 primes while up to 8192 (what is calculated), there are only 1028.
The corrected algorithm would be:
as the inner part has to mark all multiplications of the current prime. The other algorithm just does not mark many non-primes (it seems like an optimization to faster find the next prime - but it does not seem to be used correctly here...).
Also, in consequence, this cheats a bit on the result of the benchmark (by more than a 100 'ticks')...