示例#1
0
    /********************
    ** randomize_wts() **
    *********************
    ** Intialize the weights in the middle and output layers to
    ** random values between -0.25..+0.25
    ** Function rand() returns a value between 0 and 32767.
    **
    ** NOTE: Had to make alterations to how the random numbers were
    ** created.  -- RG.
    **/
    public static void randomize_wts()
    {
        int    neurode, i;
        double value;

        /*
        ** Following not used int benchmark version -- RG
        **
        **        printf("\n Please enter a random number seed (1..32767):  ");
        **        scanf("%d", &i);
        **        srand(i);
        */

        for (neurode = 0; neurode < MID_SIZE; neurode++)
        {
            for (i = 0; i < IN_SIZE; i++)
            {
                value = (double)ByteMark.abs_randwc(100000);
                value = value / (double)100000.0 - (double)0.5;
                mid_wts[neurode, i] = value / 2;
            }
        }
        for (neurode = 0; neurode < OUT_SIZE; neurode++)
        {
            for (i = 0; i < MID_SIZE; i++)
            {
                value = (double)ByteMark.abs_randwc(100000);
                value = value / (double)10000.0 - (double)0.5;
                out_wts[neurode, i] = value / 2;
            }
        }
        return;
    }
示例#2
0
    /**********************
    ** create_text_block **
    ***********************
    ** Build a block of text randomly loaded with words.  The words
    ** come from the wordcatalog (which must be loaded before you
    ** call this).
    ** *tb points to the memory where the text is to be built.
    ** tblen is the # of bytes to put into the text block
    ** maxlinlen is the maximum length of any line (line end indicated
    **  by a carriage return).
    */
    private static void create_text_block(byte[] tb,
                                          int tblen,
                                          short maxlinlen)
    {
        int bytessofar;       /* # of bytes so far */
        int linelen;          /* Line length */

        bytessofar = 0;
        do
        {
            /*
            ** Pick a random length for a line and fill the line.
            ** Make sure the line can fit (haven't exceeded tablen) and also
            ** make sure you leave room to append a carriage return.
            */
            linelen = ByteMark.abs_randwc(maxlinlen - 6) + 6;
            if ((linelen + bytessofar) > tblen)
            {
                linelen = tblen - bytessofar;
            }

            if (linelen > 1)
            {
                create_text_line(tb, linelen, bytessofar);
            }
            tb[linelen] = (byte)'\n';          /* Add the carriage return */

            bytessofar += linelen;
        } while (bytessofar < tblen);
    }
示例#3
0
    /********************
    ** LoadStringArray **
    *********************
    ** Initialize the string array with random strings of
    ** varying sizes.
    ** Returns the pointer to the offset pointer array.
    ** Note that since we're creating a number of arrays, this
    ** routine builds one array, then copies it into the others.
    */
    private static void LoadStringArray(string[][] array,          /* String array */
                                        int arraysize,             /* Size of array */
                                        int numarrays)             /* # of arrays */
    {
        /*
        ** Initialize random number generator.
        */
        ByteMark.randnum(13);

        /*
        ** Load up the first array with randoms
        */

        int i;

        for (i = 0; i < arraysize; i++)
        {
            int length;

            length      = 4 + ByteMark.abs_randwc(76);
            array[0][i] = "";

            /*
            ** Fill up the string with random bytes.
            */
            StringBuilder builder = new StringBuilder(length);

            int add;
            for (add = 0; add < length; add++)
            {
                char myChar = (char)(ByteMark.abs_randwc(96) + 32);
                builder.Append(myChar);
            }
            array[0][i] = builder.ToString();
        }

        /*
        ** We now have initialized a single full array.  If there
        ** is more than one array, copy the original into the
        ** others.
        */
        int k;

        for (k = 1; k < numarrays; k++)
        {
            for (i = 0; i < arraysize; i++)
            {
                array[k][i] = array[0][i];
            }
        }
    }
    /***************
	** LoadAssign **
	****************
	** The array given by arraybase is loaded with positive random
	** numbers.  Elements in the array are capped at 5,000,000.
	*/
    private static void LoadAssign(int[,] arraybase)
    {
        short i, j;

        /*
		** Reset random number generator so things repeat.
		*/
        ByteMark.randnum(13);

        for (i = 0; i < global.ASSIGNROWS; i++)
            for (j = 0; j < global.ASSIGNROWS; j++)
                arraybase[i, j] = ByteMark.abs_randwc(5000000);
        return;
    }
示例#5
0
    /*********************
    ** create_text_line **
    **********************
    ** Create a random line of text, stored at *dt.  The line may be
    ** no more than nchars long.
    */
    private static void create_text_line(byte[] dt, int nchars, int lower)
    {
        int    charssofar;    /* # of characters so far */
        int    tomove;        /* # of characters to move */
        string myword;        /* Local buffer for words */

        int index = 0;

        charssofar = 0;

        do
        {
            /*
            ** Grab a random word from the wordcatalog
            */
            myword = wordcatarray[ByteMark.abs_randwc(Huffman.WORDCATSIZE)];

            /*
            ** Append a blank.
            */
            myword += " ";
            tomove  = myword.Length;

            /*
            ** See how long it is.  If its length+charssofar > nchars, we have
            ** to trim it.
            */
            if ((tomove + charssofar) > nchars)
            {
                tomove = nchars - charssofar;
            }

            /*
            ** Attach the word to the current line.  Increment counter.
            */
            for (int i = 0; i < tomove; i++)
            {
                dt[lower + index++] = (byte)myword[i];
            }
            charssofar += tomove;

            /*
            ** If we're done, bail out.  Otherwise, go get another word.
            */
        } while (charssofar < nchars);

        return;
    }
示例#6
0
    private static void build_problem(double[][] a, int n, double[] b)
    {
        int    i, j, k, k1;
        double rcon;

        ByteMark.randnum(13);

        for (i = 0; i < n; i++)
        {
            b[i] = (double)(ByteMark.abs_randwc(100) + 1);
            for (j = 0; j < n; j++)
            {
                if (i == j)
                {
                    a[i][j] = (double)(ByteMark.abs_randwc(1000) + 1);
                }
                else
                {
                    a[i][j] = (double)0.0;
                }
            }
        }

        for (i = 0; i < 8 * n; i++)
        {
            k  = ByteMark.abs_randwc(n);
            k1 = ByteMark.abs_randwc(n);
            if (k != k1)
            {
                if (k < k1)
                {
                    rcon = 1.0;
                }
                else
                {
                    rcon = -1.0;
                }
                for (j = 0; j < n; j++)
                {
                    a[k][j] += a[k1][j] * rcon;
                }
                b[k] += b[k1] * rcon;
            }
        }
    }
示例#7
0
    public override double Run()
    {
        int i;

        char[] Z       = new char[global.KEYLEN];
        char[] DK      = new char[global.KEYLEN];
        char[] userkey = new char[8];
        long   accumtime;
        double iterations;

        byte[] plain1;               /* First plaintext buffer */
        byte[] crypt1;               /* Encryption buffer */
        byte[] plain2;               /* Second plaintext buffer */

        /*
        ** Re-init random-number generator.
        */
        ByteMark.randnum(3);

        /*
        ** Build an encryption/decryption key
        */
        for (i = 0; i < 8; i++)
        {
            userkey[i] = (char)(ByteMark.abs_randwc(60000) & 0xFFFF);
        }
        for (i = 0; i < global.KEYLEN; i++)
        {
            Z[i] = (char)0;
        }

        /*
        ** Compute encryption/decryption subkeys
        */
        en_key_idea(userkey, Z);
        de_key_idea(Z, DK);

        /*
        ** Allocate memory for buffers.  We'll make 3, called plain1,
        ** crypt1, and plain2.  It works like this:
        **   plain1 >>encrypt>> crypt1 >>decrypt>> plain2.
        ** So, plain1 and plain2 should match.
        ** Also, fill up plain1 with sample text.
        */
        plain1 = new byte[this.arraysize];
        crypt1 = new byte[this.arraysize];
        plain2 = new byte[this.arraysize];

        /*
        ** Note that we build the "plaintext" by simply loading
        ** the array up with random numbers.
        */
        for (i = 0; i < this.arraysize; i++)
        {
            plain1[i] = (byte)(ByteMark.abs_randwc(255) & 0xFF);
        }

        /*
        ** See if we need to perform self adjustment loop.
        */
        if (this.adjust == 0)
        {
            /*
            ** Do self-adjustment.  This involves initializing the
            ** # of loops and increasing the loop count until we
            ** get a number of loops that we can use.
            */
            for (this.loops = 100;
                 this.loops < global.MAXIDEALOOPS;
                 this.loops += 10)
            {
                if (DoIDEAIteration(plain1, crypt1, plain2,
                                    this.arraysize,
                                    this.loops,
                                    Z, DK) > global.min_ticks)
                {
                    break;
                }
            }
        }

        /*
        ** All's well if we get here.  Do the test.
        */
        accumtime  = 0;
        iterations = (double)0.0;

        do
        {
            accumtime += DoIDEAIteration(plain1, crypt1, plain2,
                                         this.arraysize,
                                         this.loops, Z, DK);
            iterations += (double)this.loops;
        } while (ByteMark.TicksToSecs(accumtime) < this.request_secs);

        /*
        ** Clean up, calculate results, and go home.  Be sure to
        ** show that we don't have to rerun adjustment code.
        */

        if (this.adjust == 0)
        {
            this.adjust = 1;
        }

        return(iterations / ByteMark.TicksToFracSecs(accumtime));
    }
示例#8
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));
    }