示例#1
0
    /**********************
    ** DoAssignIteration **
    ***********************
    ** This routine executes one iteration of the assignment test.
    ** It returns the number of ticks elapsed in the iteration.
    */
    private static long DoAssignIteration(int[][,] arraybase, int numarrays)
    {
        long elapsed;                   /* Elapsed ticks */
        int  i;

        /*
        ** Load up the arrays with a random table.
        */
        LoadAssignArrayWithRand(arraybase, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute assignment algorithms
        */
        for (i = 0; i < numarrays; i++)
        {
            Assignment(arraybase[i]);
        }

        /*
        ** Get elapsed time
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
示例#2
0
    long DoEmFloatIteration(InternalFPF[] abase,
                            InternalFPF[] bbase,
                            InternalFPF[] cbase,
                            int arraysize, int loops)
    {
        long elapsed;          /* For the stopwatch */

        byte[] jtable = new byte[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3 };
        int    i;

        /*
        ** Begin timing
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Each pass through the array performs operations in
        ** the followingratios:
        **   4 adds, 4 subtracts, 5 multiplies, 3 divides
        ** (adds and subtracts being nearly the same operation)
        */
        while (loops-- > 0)
        {
            for (i = 0; i < arraysize; i++)
            {
                switch (jtable[i % 16])
                {
                case 0:     /* Add */
                    AddSubInternalFPF(0, abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;

                case 1:     /* Subtract */
                    AddSubInternalFPF(1, abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;

                case 2:     /* Multiply */
                    MultiplyInternalFPF(abase[i],
                                        bbase[i],
                                        cbase[i]);
                    break;

                case 3:     /* Divide */
                    DivideInternalFPF(abase[i],
                                      bbase[i],
                                      cbase[i]);
                    break;
                }
            }
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
示例#3
0
    /********************
    ** DoIDEAIteration **
    *********************
    ** Execute a single iteration of the IDEA encryption algorithm.
    ** Actually, a single iteration is one encryption and one
    ** decryption.
    */
    private static long DoIDEAIteration(byte[] plain1,
                                        byte[] crypt1,
                                        byte[] plain2,
                                        int arraysize,
                                        int nloops,
                                        char[] Z,
                                        char[] DK)
    {
        int  i;
        int  j;
        long elapsed;

        /*
        ** Start the stopwatch.
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Do everything for nloops.
        */

        for (i = 0; i < nloops; i++)
        {
            for (j = 0; j < arraysize; j += 8)
            {
                cipher_idea(plain1, crypt1, j, Z);  /* Encrypt */
            }
            for (j = 0; j < arraysize; j += 8)
            {
                cipher_idea(crypt1, plain2, j, DK);  /* Decrypt */
            }
        }

        // Validate output
        for (j = 0; j < arraysize; j++)
        {
            if (plain1[j] != plain2[j])
            {
                string error = String.Format("IDEA: error at index {0} ({1} <> {2})!", j, (int)plain1[j], (int)plain2[j]);
                throw new Exception(error);
            }
        }

        /*
        ** Get elapsed time.
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
    /***********************
    ** DoNumSortIteration **
    ************************
    ** This routine executes one iteration of the numeric
    ** sort benchmark.  It returns the number of ticks
    ** elapsed for the iteration.
    */

    // JTR: The last 2 parms are no longer needed as they
    // can be inferred from the arraybase. <shrug>
    private static int DoNumSortIteration(int[,] arraybase, int arraysize, int numarrays)
    {
        long elapsed;          /* Elapsed ticks */
        int  i;

        /*
        ** Load up the array with random numbers
        */
        LoadNumArrayWithRand(arraybase, arraysize, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute a heap of heapsorts
        */
        for (i = 0; i < numarrays; i++)
        {
            //          NumHeapSort(arraybase+i*arraysize,0L,arraysize-1L);
            NumHeapSort(arraybase, i, arraysize - 1);
        }

        /*
        ** Get elapsed time
        */
        elapsed = ByteMark.StopStopwatch(elapsed);
#if DEBUG
        {
            for (i = 0; i < arraysize - 1; i++)
            {   /*
                ** Compare to check for proper
                ** sort.
                */
                if (arraybase[0, i + 1] < arraybase[0, i])
                {
                    Console.Write("size: {0}, count: {1}, total: {2}\n", arraysize, numarrays, arraybase.Length);
                    Console.Write("Sort Error at index {0}\n", i);
                    break;
                }
            }
        }
#endif

        return((int)elapsed);
    }
示例#5
0
    /**************************
    ** DoStringSortIteration **
    ***************************
    ** This routine executes one iteration of the string
    ** sort benchmark.  It returns the number of ticks
    ** Note that this routine also builds the offset pointer
    ** array.
    */

    private static int DoStringSortIteration(string[][] arraybase, int numarrays, int arraysize)
    {
        long elapsed;            /* Elapsed ticks */
        int  i;

        /*
        ** Load up the array(s) with random numbers
        */
        LoadStringArray(arraybase, arraysize, numarrays);

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Execute heapsorts
        */
        for (i = 0; i < numarrays; i++)
        {
            // StrHeapSort(tempobase,tempsbase,nstrings,0L,nstrings-1);
            StrHeapSort(arraybase[i], 0, arraysize - 1);
        }

        /*
        ** Record elapsed time
        */
        elapsed = ByteMark.StopStopwatch(elapsed);

#if DEBUG
        for (i = 0; i < arraysize - 1; i++)
        {
            /*
            ** Compare strings to check for proper
            ** sort.
            */
            if (StringOrdinalComparer.Compare(arraybase[0][i + 1], arraybase[0][i]) < 0)
            {
                Console.Write("Error in StringSort!  arraybase[0][{0}]='{1}', arraybase[0][{2}]='{3}\n", i, arraybase[0][i], i + 1, arraybase[0][i + 1]);
                break;
            }
        }
#endif

        return((int)elapsed);
    }
示例#6
0
    /*
    ** Perform an iteration of the FPU Transcendental/trigonometric
    ** benchmark.  Here, an iteration consists of calculating the
    ** first n fourier coefficients of the function (x+1)^x on
    ** the interval 0,2.  n is given by arraysize.
    ** NOTE: The # of integration steps is fixed at
    ** 200.
    */
    private static long DoFPUTransIteration(double[] abase, double[] bbase, int arraysize)
    {
        double omega;   /* Fundamental frequency */
        int    i;       /* Index */
        long   elapsed; /* Elapsed time */

        elapsed = ByteMark.StartStopwatch();

        /*
        ** Calculate the fourier series.  Begin by
        ** calculating A[0].
        */

        abase[0] = TrapezoidIntegrate(0.0, 2.0, 200, 0.0, 0) / 2.0;

        /*
        ** Calculate the fundamental frequency.
        ** ( 2 * pi ) / period...and since the period
        ** is 2, omega is simply pi.
        */
        omega = 3.1415926535897921;

        for (i = 1; i < arraysize; i++)
        {
            /*
            ** Calculate A[i] terms.  Note, once again, that we
            ** can ignore the 2/period term outside the integral
            ** since the period is 2 and the term cancels itself
            ** out.
            */
            abase[i] = TrapezoidIntegrate(0.0, 2.0, 200, omega * (double)i, 1);

            bbase[i] = TrapezoidIntegrate(0.0, 2.0, 200, omega * (double)i, 2);
        }

        /*
        ** All done, stop the stopwatch
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
    /********************
    ** DoNNetIteration **
    *********************
    ** Do a single iteration of the neural net benchmark.
    ** By iteration, we mean a "learning" pass.
    */
    public static long DoNNetIteration(long nloops)
    {
        long elapsed;          /* Elapsed time */
        int  patt;

        /*
        ** Run nloops learning cycles.  Notice that, counted with
        ** the learning cycle is the weight randomization and
        ** zeroing of changes.  This should reduce clock jitter,
        ** since we don't have to stop and start the clock for
        ** each iteration.
        */
        elapsed = ByteMark.StartStopwatch();
        while (nloops-- != 0)
        {
            randomize_wts();
            zero_changes();
            iteration_count = 1;
            learned         = F;
            numpasses       = 0;
            while (learned == F)
            {
                for (patt = 0; patt < numpats; patt++)
                {
                    worst_error = 0.0;      /* reset this every pass through data */
                    move_wt_changes();      /* move last pass's wt changes to momentum array */
                    do_forward_pass(patt);
                    do_back_pass(patt);
                    iteration_count++;
                }
                numpasses++;
                learned = check_out_error();
            }
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
示例#8
0
    private static long DoLUIteration(double[][] a, double[] b, double[][][] abase, double[][] bbase, int numarrays)
    {
        double[][] locabase;
        double[]   locbbase;
        long       elapsed;
        int        k, j, i;

        for (j = 0; j < numarrays; j++)
        {
            locabase = abase[j];
            locbbase = bbase[j];
            for (i = 0; i < global.LUARRAYROWS; i++)
            {
                for (k = 0; k < global.LUARRAYCOLS; k++)
                {
                    locabase[i][k] = a[i][k];
                }
            }
            for (i = 0; i < global.LUARRAYROWS; i++)
            {
                locbbase[i] = b[i];
            }
        }

        elapsed = ByteMark.StartStopwatch();

        for (i = 0; i < numarrays; i++)
        {
            locabase = abase[i];
            locbbase = bbase[i];

            lusolve(locabase, global.LUARRAYROWS, locbbase);
        }

        return(ByteMark.StopStopwatch(elapsed));
    }
示例#9
0
    /********************
    ** DoHuffIteration **
    *********************
    ** Perform the huffman benchmark.  This routine
    **  (a) Builds the huffman tree
    **  (b) Compresses the text
    **  (c) Decompresses the text and verifies correct decompression
    */
    private static long DoHuffIteration(byte[] plaintext,
                                        byte[] comparray,
                                        byte[] decomparray,
                                        int arraysize,
                                        int nloops,
                                        huff_node[] hufftree)
    {
        int   i;                         /* Index */
        int   j;                         /* Bigger index */
        int   root;                      /* Pointer to huffman tree root */
        float lowfreq1, lowfreq2;        /* Low frequency counters */
        int   lowidx1, lowidx2;          /* Indexes of low freq. elements */
        int   bitoffset;                 /* Bit offset into text */
        int   textoffset;                /* Char offset into text */
        int   maxbitoffset;              /* Holds limit of bit offset */
        int   bitstringlen;              /* Length of bitstring */
        int   c;                         /* Character from plaintext */

        byte[] bitstring = new byte[30]; /* Holds bitstring */
        long   elapsed;                  /* For stopwatch */

        /*
        ** Start the stopwatch
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Do everything for nloops
        */
        while (nloops-- != 0)
        {
            /*
            ** Calculate the frequency of each byte value. Store the
            ** results in what will become the "leaves" of the
            ** Huffman tree.  Interior nodes will be built in those
            ** nodes greater than node #255.
            */
            for (i = 0; i < 256; i++)
            {
                hufftree[i].freq = (float)0.0;
                hufftree[i].c    = (byte)i;
            }

            for (j = 0; j < arraysize; j++)
            {
                hufftree[plaintext[j]].freq += (float)1.0;
            }

            for (i = 0; i < 256; i++)
            {
                if (hufftree[i].freq != (float)0.0)
                {
                    hufftree[i].freq /= (float)arraysize;
                }
            }

            /*
            ** Build the huffman tree.  First clear all the parent
            ** pointers and left/right pointers.  Also, discard all
            ** nodes that have a frequency of true 0.
            */
            for (i = 0; i < 512; i++)
            {
                if (hufftree[i].freq == (float)0.0)
                {
                    hufftree[i].parent = EXCLUDED;
                }
                else
                {
                    hufftree[i].parent = hufftree[i].left = hufftree[i].right = -1;
                }
            }

            /*
            ** Go through the tree. Finding nodes of really low
            ** frequency.
            */
            root = 255;                       /* Starting root node-1 */
            while (true)
            {
                lowfreq1 = (float)2.0; lowfreq2 = (float)2.0;
                lowidx1  = -1; lowidx2 = -1;

                /*
                ** Find first lowest frequency.
                */
                for (i = 0; i <= root; i++)
                {
                    if (hufftree[i].parent < 0)
                    {
                        if (hufftree[i].freq < lowfreq1)
                        {
                            lowfreq1 = hufftree[i].freq;
                            lowidx1  = i;
                        }
                    }
                }

                /*
                ** Did we find a lowest value?  If not, the
                ** tree is done.
                */
                if (lowidx1 == -1)
                {
                    break;
                }

                /*
                ** Find next lowest frequency
                */
                for (i = 0; i <= root; i++)
                {
                    if ((hufftree[i].parent < 0) && (i != lowidx1))
                    {
                        if (hufftree[i].freq < lowfreq2)
                        {
                            lowfreq2 = hufftree[i].freq;
                            lowidx2  = i;
                        }
                    }
                }

                /*
                ** If we could only find one item, then that
                ** item is surely the root, and (as above) the
                ** tree is done.
                */
                if (lowidx2 == -1)
                {
                    break;
                }

                /*
                ** Attach the two new nodes to the current root, and
                ** advance the current root.
                */
                root++;                 /* New root */
                hufftree[lowidx1].parent = root;
                hufftree[lowidx2].parent = root;
                hufftree[root].freq      = lowfreq1 + lowfreq2;
                hufftree[root].left      = lowidx1;
                hufftree[root].right     = lowidx2;
                hufftree[root].parent    = -2;    /* Show root */
            }

            /*
            ** Huffman tree built...compress the plaintext
            */
            bitoffset = 0;                           /* Initialize bit offset */
            for (i = 0; i < arraysize; i++)
            {
                c = (int)plaintext[i];                 /* Fetch character */

                /*
                ** Build a bit string for byte c
                */
                bitstringlen = 0;
                while (hufftree[c].parent != -2)
                {
                    if (hufftree[hufftree[c].parent].left == c)
                    {
                        bitstring[bitstringlen] = (byte)'0';
                    }
                    else
                    {
                        bitstring[bitstringlen] = (byte)'1';
                    }
                    c = hufftree[c].parent;
                    bitstringlen++;
                }

                /*
                ** Step backwards through the bit string, setting
                ** bits in the compressed array as you go.
                */
                while (bitstringlen-- != 0)
                {
                    SetCompBit(comparray, bitoffset, bitstring[bitstringlen]);
                    bitoffset++;
                }
            }

            /*
            ** Compression done.  Perform de-compression.
            */
            maxbitoffset = bitoffset;
            bitoffset    = 0;
            textoffset   = 0;
            do
            {
                i = root;
                while (hufftree[i].left != -1)
                {
                    if (GetCompBit(comparray, bitoffset) == 0)
                    {
                        i = hufftree[i].left;
                    }
                    else
                    {
                        i = hufftree[i].right;
                    }
                    bitoffset++;
                }
                decomparray[textoffset] = hufftree[i].c;

#if DEBUG
                if (hufftree[i].c != plaintext[textoffset])
                {
                    /* Show error */
                    string error = String.Format("Huffman: error at textoffset {0}", textoffset);
                    throw new Exception(error);
                }
#endif
                textoffset++;
            } while (bitoffset < maxbitoffset);
        }       /* End the big while(nloops--) from above */

        /*
        ** All done
        */
        return(ByteMark.StopStopwatch(elapsed));
    }
示例#10
0
    /************************
    ** DoBitfieldIteration **
    *************************
    ** Perform a single iteration of the bitfield benchmark.
    ** Return the # of ticks accumulated by the operation.
    */
    private static long DoBitfieldIteration(int[] bitarraybase,
                                            int[] bitoparraybase,
                                            int bitoparraysize,
                                            ref int nbitops)
    {
        int  i;                        /* Index */
        int  bitoffset;                /* Offset into bitmap */
        long elapsed;                  /* Time to execute */

        /*
        ** Clear # bitops counter
        */
        nbitops = 0;

        /*
        ** Construct a set of bitmap offsets and run lengths.
        ** The offset can be any random number from 0 to the
        ** size of the bitmap (in bits).  The run length can
        ** be any random number from 1 to the number of bits
        ** between the offset and the end of the bitmap.
        ** Note that the bitmap has 8192 * 32 bits in it.
        ** (262,144 bits)
        */
        for (i = 0; i < bitoparraysize; i++)
        {
            /* First item is offset */
            bitoparraybase[i + i] = bitoffset = ByteMark.abs_randwc(262140);

            /* Next item is run length */
            nbitops += bitoparraybase[i + i + 1] = ByteMark.abs_randwc(262140 - bitoffset);
        }

        /*
        ** Array of offset and lengths built...do an iteration of
        ** the test.
        ** Start the stopwatch.
        */
        elapsed = ByteMark.StartStopwatch();

        /*
        ** Loop through array off offset/run length pairs.
        ** Execute operation based on modulus of index.
        */
        for (i = 0; i < bitoparraysize; i++)
        {
            switch (i % 3)
            {
            case 0:     /* Set run of bits */
                ToggleBitRun(bitarraybase,
                             bitoparraybase[i + i],
                             bitoparraybase[i + i + 1],
                             1);
                break;

            case 1:     /* Clear run of bits */
                ToggleBitRun(bitarraybase,
                             bitoparraybase[i + i],
                             bitoparraybase[i + i + 1],
                             0);
                break;

            case 2:     /* Complement run of bits */
                FlipBitRun(bitarraybase,
                           bitoparraybase[i + i],
                           bitoparraybase[i + i + 1]);
                break;
            }
        }

        /*
        ** Return elapsed time
        */
        return(ByteMark.StopStopwatch(elapsed));
    }