public static void TestArrayCopyBlockCopy1(int iterationCount = 1)
        {
            Console.WriteLine("---------------------------------------------------------------");
            Console.WriteLine("Copy array using block copy -- :");
            Console.WriteLine("Generating data ... ");
            dh.StartWatch();
            int n = 1024 * 1024;
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            rnd.Reset();
            byte[] destArray  = new byte[n];
            byte[] sourceArra = new byte[256];
            Buffer.BlockCopy(rnd.values, 0, sourceArra, 0, 256);

            byte index    = rnd.bNext();
            int  position = 0;

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Executing - > ... ");

            dh.StartWatch();

            for (int k = iterationCount * 1024; k > 0; --k)
            {
                position = n;
                //index = rnd.bNext();
                index     = 1;
                position -= index;
                while (position > 0)
                {
                    Buffer.BlockCopy(sourceArra, 0, destArray, position, index);
                    index     = rnd.bNext();
                    position -= index;
                }
            }

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            destArray = null;
            GarbachCollectorHelper.GBForceRun();
        }
        public static void TestArrayCopyIndexing1(int iterationCount = 1)
        {
            Console.WriteLine("---------------------------------------------------------------");
            Console.WriteLine("Copy array using for(i++) :");
            Console.WriteLine("Generating data ... ");
            dh.StartWatch();
            int n = 1024 * 1024 * 1024;
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            rnd.Reset();
            byte[] destArray  = new byte[1024 * 1024 * 1024];
            byte[] sourceArra = new byte[256];
            Buffer.BlockCopy(rnd.values, 0, sourceArra, 0, 256);

            byte index    = rnd.bNext();
            int  position = 0;

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Executing --i > ... ");


            dh.StartWatch();

            for (int k = iterationCount; k > 0; --k)
            {
                position = n;
                while (position - index >= 0)
                {
                    for (byte j = index; j > 0; --j)
                    {
                        --position;
                        destArray[position] = sourceArra[j];
                    }
                    index = rnd.bNext();
                }
            }

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            destArray = null;
            GarbachCollectorHelper.GBForceRun();
        }
Exemplo n.º 3
0
        unsafe public static void TestArrayCopyFixed1(int iterationCount = 1)
        {
            Console.WriteLine("---------------------------------------------------------------");
            Console.WriteLine("Copy array using pointer copy ++:");
            Console.WriteLine("Generating data ... ");
            dh.StartWatch();
            int n = 1024 * 1024 * 1024;
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            rnd.Reset();
            byte[] destArray   = new byte[1024 * 1024 * 1024];
            byte[] sourceArray = new byte[256];
            Buffer.BlockCopy(rnd.values, 0, sourceArray, 0, 256);

            byte  index       = rnd.bNext();
            byte *endDest     = null;
            byte *endSrc      = null;
            byte *currentSrc  = null;
            byte *currentDest = null;


            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());


            Console.WriteLine("Executing + ... ");


            dh.StartWatch();
            for (int k = iterationCount; k != 0; --k)
            {
                endDest     = null;
                currentSrc  = null;
                currentDest = null;
                index       = rnd.bNext();
                fixed(byte *startDest = &destArray[0], startSource = &sourceArray[0])
                {
                    endDest = startDest + n - 1;
                    endSrc  = startSource + index;

                    currentDest = startDest;
                    do
                    {
                        currentSrc = startSource;
                        endSrc     = startSource + index;
                        while (currentSrc <= endSrc)
                        {
                            *currentDest = *currentSrc;
                            ++currentDest;
                            ++currentSrc;
                        }

                        index = rnd.bNext();
                    }while ((currentDest + index) <= endDest);
                }
            }

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            destArray = null;
            GarbachCollectorHelper.GBForceRun();
        }