/**
 *  Benchmark #1 - Prime number computed using Eratosthen's sieve (alternative).
 *   @author  Josef.Pelikan@mff.cuni.cz
 *   @version 0.008 (2001/06/29)
 *   @since   0.008
 */
public class BenchmarkEratosthenAlt extends BenchmarkEratosthen {

    /** Maximum bit-mask size. */
    protected final static int PRIME_ASSERT = 50000000;

    /**
     *  Initializing constructor.
     */
    public BenchmarkEratosthenAlt () {
    }

    /**
     *  The benchmark algorithm itself. Needs not be re-entrant but can be iterated.
     */
    protected void test () {
        BitMask sieve = new BitMask();
        sieve.assert(2);
        sieve.assert(PRIME_ASSERT);
        int n = 1;
        prime = 1;
        do {                                // find the next prime
            do prime++;
            while ( sieve.getUnsafe(prime) );
            int k = prime;
            int step = prime + prime - 1;
            do {
                sieve.setUnsafe(k,true);
                k += step;
                } while ( k <= PRIME_ASSERT );
            } while ( ++n < PRIME_ORDER );
        prime += prime - 1;
    }

}
