/**
 *  Benchmark #6 - Fast memory copy.
 *   @author  Josef.Pelikan@mff.cuni.cz
 *   @version 0.007 (2001/06/17)
 *   @since   0.007
 */
public class BenchmarkMemoryCopy extends Benchmark {

    /** Array size in bytes. */
    protected final static int MEM_COPY_MAX = 16 << 20;

    /** Number of iterations. */
    protected final static int MEM_COPY_ITER = 100;

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

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

    /**
     *  The benchmark algorithm itself. Needs not be re-entrant but can be iterated.
     */
    protected void test () {
        byte[] a = new byte[MEM_COPY_MAX];
        byte[] b = new byte[MEM_COPY_MAX];
        int i;
        for ( i = 0; i++ < MEM_COPY_ITER; ) {
            System.arraycopy(a,0,b,0,MEM_COPY_MAX);
            System.arraycopy(b,0,a,0,MEM_COPY_MAX);
            }
    }

    /**
     *  Result string of the test. Should be called after the <code>runTest()</code>
     *  was finished.
     *   @return Result of the test.
     */
    public String testResult () {
        return( "Fast mem-copy: array size = " + (MEM_COPY_MAX>>20) +
                " MB, iterations = " + MEM_COPY_ITER );
    }

}
