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

    /** Order of the computed prime number. */
    protected final static int PRIME_ORDER = 5555555;

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

    /** The computed prime number. */
    protected int prime;

    /**
     *  Initializing constructor.
     */
    public BenchmarkEratosthen () {
        prime = 0;
    }

    /**
     *  Test (benchmark) ordinal number.
     *   @return Ordinal number of the test.
     */
    public int testNumber () {
        return 1;
    }

    /**
     *  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 = 0;
        prime = 1;
        do {                                // find the next prime
            do prime++;
            while ( sieve.getUnsafe(prime) );
            int k = prime;
            do {
                sieve.setUnsafe(k,true);
                k += prime;
                } while ( k <= PRIME_ASSERT );
            } while ( ++n < PRIME_ORDER );
    }

    /**
     *  Result string of the test. Should be called after the <code>runTest()</code>
     *  was finished.
     *   @return Result of the test.
     */
    public String testResult () {
        return( "The " + PRIME_ORDER + "-th prime number is: " + prime );
    }

}
