public static void TestQuickSort(int n)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Comparer  Quick Sort");
            int[] array = new int[n];
            Console.WriteLine("Generate data");
            RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1);
            FastRandom rnd = new FastRandom();

            dh.StartWatch();
            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Sort");
            dh.StartWatch();
            var c = new CustomIntComparerD();

            Quicksort(array, 0, n - 1, c.Compare);
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
예제 #2
0
        unsafe public static void TestQuickSort(int n)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Pointer Quick Sort");
            int[] array = new int[n];
            Console.WriteLine("Generate data");
            dh.StartWatch();
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1);

            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next32();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Sort");
            dh.StartWatch();
            fixed(int *start = &array[0], end = &array[n - 1])
            {
                Quicksort(start, end);
            }

            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
        public static void TestRandomBytesProducer()
        {
            RandomBytesProducer.InitBytes();
            dh.StartWatch();
            //ulong n = (ulong)20 * (ulong)1024 * (ulong)1024 * (ulong)1024;
            ulong n = (ulong)1024 * (ulong)1024 * (ulong)1024;

            byte[] tmp = null;
            RandomIteratorUsafeXorshiftEn randomIteratorUsafeXorshiftEn = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            for (ulong i = 0; i < n; i++)
            {
                tmp = RandomBytesProducer.GetByte(randomIteratorUsafeXorshiftEn.Next16());
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        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();
        }
        public static void TestSort(int n)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Comparer Sort");
            int[] array = new int[n];
            Console.WriteLine("Generate data");

            RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1);
            FastRandom rnd    = new FastRandom();
            Random     random = new Random();

            dh.StartWatch();
            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            /*
             * byte[] byteArray = new byte[256];
             * dh.StartWatch();
             * for (int i = 0; i < n; i++)
             * {
             *  array[i] = byteArray[rnd1.bNext()];
             * }
             * dh.StoptWatch();
             * Console.WriteLine(dh.GetMessage());
             *
             * dh.StartWatch();
             * for (int i = 0; i < n; i++)
             * {
             *  array[i] = rnd1.Next16();
             * }
             * dh.StoptWatch();
             * Console.WriteLine(dh.GetMessage());
             */
            Console.WriteLine("Sort");
            dh.StartWatch();
            Array.Sort(array, new CustomIntComparerD());
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
예제 #7
0
        public static void TestQuickSort(int n)
        {
            var cc = new CustomIntComparerPointer();
            CustomCompareDelegate del = new CustomCompareDelegate(cc.Compare);

            IntPtr ptr = Marshal.GetFunctionPointerForDelegate(del);

            // Получили указатель на ту самую функцию
            void *p = ptr.ToPointer();

            var d = (CustomCompareDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)p, typeof(CustomCompareDelegate));

            Console.WriteLine(d(2, 3));

            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Comparer  Quick Sort");
            int[] array = new int[n];
            Console.WriteLine("Generate data");
            RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1);
            FastRandom rnd = new FastRandom();

            dh.StartWatch();
            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Sort");
            dh.StartWatch();
            var c = new CustomIntComparerPointer();

            Quicksort(array, 0, n - 1, d);
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
예제 #8
0
        public static void TestQuickSortTaskLimited(int n, int limit)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Pointer Quick Sort Limited ");
            int[] array = new int[n];
            Console.WriteLine("Generate data");
            dh.StartWatch();
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1);

            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next32();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Sort");
            dh.StartWatch();
            QuicksortTaskLimited(array, 0, n - 1, limit);
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
예제 #9
0
        public static void TestSort(int n)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Test Pointer Sort  ");
            int[] array = new int[n];
            Console.WriteLine("Generate data");
            dh.StartWatch();
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1);

            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next32();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Sort");
            dh.StartWatch();
            Array.Sort(array);
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            array = null;
            GarbachCollectorHelper.GBForceRun();
        }
        unsafe public static bool AddNewLine(int randomIndex, ref int templateLenghtCh, ref int position, int minStrLength, byte[] buffer, RandomIteratorUsafeXorshiftEn rnd, byte[][] templateCh, int *psize, int *psize2, int *pdic)
        {
            bool result = false;

            if (position > 2)
            {
                --position;
                buffer[position] = 10;
                --position;
                buffer[position] = 13;
            }
            templateLenghtCh = *(psize + randomIndex);
            position        -= templateLenghtCh;
            while (position >= minStrLength)
            {
                Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position, templateLenghtCh);
                result = true;
                if (rnd.NextBool())
                {
                    templateLenghtCh = *(psize + randomIndex);
                    position        -= templateLenghtCh;
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
        unsafe public static void TestBytesGeneratorStrongInline(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200)
        {
            dh.StartWatch();
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            RandomBytesProducer.InitBytes();
            //-------
            int maxLengthCh2 = (int)maxLengthCh << 1;

            Console.WriteLine("Test Bytes Generator strong Inline :");
            Console.WriteLine("Generating Data ...");
            byte[] buffer = new byte[maxLengthCh];


            GCHandle gchbuffers     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   addrBuffer     = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)maxLengthCh - 1);
            char *   pBuffer        = (char *)addrBuffer.ToPointer();
            char *   pCurrentBuffer = pBuffer;
            char *   pBufferStart   = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);

            string[] _templateCh = new string[10]
            {
                " apple"
                , " town"
                , " array"
                , " summer"
                , " winter"
                , " april"
                , " customer"
                , " support"
                , " laptop"
                , " cross-domain"
            };

            byte[][] templateCh = DataProducer.ConvetStringListToBytes(_templateCh);
            int      n          = templateCh.Length;

            int[]    sizes     = new int[n];
            GCHandle gchsizes  = GCHandle.Alloc(sizes, GCHandleType.Pinned);
            IntPtr   addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0);
            int *    pSize     = (int *)addrSizes.ToPointer();

            int[]    sizes2     = new int[n];
            GCHandle gchsizes2  = GCHandle.Alloc(sizes2, GCHandleType.Pinned);
            IntPtr   addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0);
            int *    pSizes2    = (int *)addrSizes2.ToPointer();

            int sizeTmp = 0;

            for (int i = 0; i < n; i++)
            {
                sizeTmp   = templateCh[i].Length;
                sizes[i]  = sizeTmp;
                sizes2[i] = sizeTmp << 1;
            }

            int[] randomizeDictionary      = new int[256 * 256];
            int[] randomizeDictionarySize  = new int[256 * 256];
            int[] randomizeDictionarySize2 = new int[256 * 256];

            int k = 0;

            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionary[j] = k;
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }
            k = 0;
            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionarySize[j] = (int)sizes[k];
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }
            k = 0;
            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionarySize2[j] = (int)sizes2[k];
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Executing ... ");
            dh.StartWatch();
            int position         = maxLengthCh;
            int templateLenghtCh = (int)templateCh.Length;
            int randomIndex      = 0;

            byte[] endline = Encoding.ASCII.GetBytes(Environment.NewLine);

            GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned);

            byte[] dot = Encoding.ASCII.GetBytes(".");

            GCHandle gchdot    = GCHandle.Alloc(endline, GCHandleType.Pinned);
            GCHandle gchrndInt = GCHandle.Alloc(endline, GCHandleType.Pinned);

            int  minStrLength = 1 + 1 + 2 + sizes[0];
            int  numberLength = 0;
            int  rndNumber    = 0;
            bool AddedLine    = false;

            fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary)
            {
                for (int i = 0; i < iteration; i++)
                {
                    position = maxLengthCh;
                    //AddEndLine(ref position, endline, buffer);
                    while (position >= minStrLength)
                    {
                        //-----------

                        AddedLine = false;
                        if (position > 2)
                        {
                            --position;
                            buffer[position] = 10;
                            --position;
                            buffer[position] = 13;
                        }
                        templateLenghtCh = *(psize + randomIndex);
                        position        -= templateLenghtCh;
                        while (position >= minStrLength)
                        {
                            Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position, templateLenghtCh);
                            AddedLine = true;
                            if (rnd.NextBool())
                            {
                                templateLenghtCh = *(psize + randomIndex);
                                position        -= templateLenghtCh;
                            }
                            else
                            {
                                break;
                            }
                        }

                        //-----------
                        if (AddedLine)
                        //if (AddNewLine(rnd.Next16(), ref templateLenghtCh, ref position, minStrLength, buffer, rnd, templateCh, psize, psize2, pdic))
                        {
                            if (position > 0)
                            {
                                --position;
                                buffer[position] = 46;
                            }
                            rndNumber    = rnd.Next16();
                            numberLength = RandomBytesProducer.byteListSizes[rndNumber];
                            if (position > numberLength)
                            {
                                position -= numberLength;
                                Buffer.BlockCopy(RandomBytesProducer.byteList[rndNumber], 0, buffer, position, numberLength);
                            }

                            //AddEndLine(ref position, endline, buffer);
                        }
                    }

                    /*
                     * if(position < 0)
                     * {
                     *  pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ;
                     *  while(pCurrentBuffer >= pBufferStart)
                     *  {
                     * pCurrentBuffer = '*';
                     *      pCurrentBuffer--;
                     *  }
                     * }*/
                }
            }

            dh.StoptWatch();
            templateCh = null;
            buffer     = null;
            templateCh = null;
            sizes      = null;
            sizes2     = null;
            if (gchrndInt.IsAllocated)
            {
                gchrndInt.Free();
            }
            if (gchdot.IsAllocated)
            {
                gchdot.Free();
            }
            if (gchendline.IsAllocated)
            {
                gchendline.Free();
            }

            if (gchsizes2.IsAllocated)
            {
                gchsizes2.Free();
            }

            if (gchsizes.IsAllocated)
            {
                gchsizes.Free();
            }

            if (gchbuffers.IsAllocated)
            {
                gchbuffers.Free();
            }

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        unsafe public static void TestBytesGenerator(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200)
        {
            RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024);

            RandomBytesProducer.InitBytes();
            //-------
            int maxLengthCh2 = (int)maxLengthCh << 1;

            Console.WriteLine("Test Bytes Generator :");
            byte[] buffer = new byte[maxLengthCh];


            GCHandle gchbuffers     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   addrBuffer     = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)maxLengthCh - 1);
            char *   pBuffer        = (char *)addrBuffer.ToPointer();
            char *   pCurrentBuffer = pBuffer;
            char *   pBufferStart   = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);

            string[] _templateCh = new string[10]
            {
                " apple"
                , " town"
                , " array"
                , " summer"
                , " winter"
                , " april"
                , " customer"
                , " support"
                , " laptop"
                , " cross-domain"
            };

            byte[][] templateCh = DataProducer.ConvetStringListToBytes(_templateCh);
            int      n          = templateCh.Length;

            int[]    sizes     = new int[n];
            GCHandle gchsizes  = GCHandle.Alloc(sizes, GCHandleType.Pinned);
            IntPtr   addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0);
            int *    pSize     = (int *)addrSizes.ToPointer();

            int[]    sizes2     = new int[n];
            GCHandle gchsizes2  = GCHandle.Alloc(sizes2, GCHandleType.Pinned);
            IntPtr   addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0);
            int *    pSizes2    = (int *)addrSizes2.ToPointer();

            int sizeTmp = 0;

            for (int i = 0; i < n; i++)
            {
                sizeTmp   = templateCh[i].Length;
                sizes[i]  = sizeTmp;
                sizes2[i] = sizeTmp << 1;
            }

            int[] randomizeDictionary      = new int[256 * 256];
            int[] randomizeDictionarySize  = new int[256 * 256];
            int[] randomizeDictionarySize2 = new int[256 * 256];

            int k = 0;

            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionary[j] = k;
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }
            k = 0;
            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionarySize[j] = (int)sizes[k];
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }
            k = 0;
            for (int j = 0; j < 256 * 256; j++)
            {
                randomizeDictionarySize2[j] = (int)sizes2[k];
                k++;
                if (k == n)
                {
                    k = 0;
                }
            }

            dh.StartWatch();
            int position         = maxLengthCh;
            int templateLenghtCh = (int)templateCh.Length;
            int randomIndex      = 0;

            byte[] endline = Encoding.ASCII.GetBytes(Environment.NewLine);

            GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned);

            byte[] dot = Encoding.ASCII.GetBytes(".");

            GCHandle gchdot    = GCHandle.Alloc(endline, GCHandleType.Pinned);
            GCHandle gchrndInt = GCHandle.Alloc(endline, GCHandleType.Pinned);

            int minStrLength = 0;

            fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary)
            {
                for (int i = 0; i < iteration; i++)
                {
                    position = maxLengthCh;
                    AddEndLine();
                    while (position >= minStrLength)
                    {
                        if (AddNewLine(psize, psize2, pdic))
                        {
                            AddNumber();
                            AddEndLine();
                        }
                    }

                    /*
                     * if(position < 0)
                     * {
                     *  pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ;
                     *  while(pCurrentBuffer >= pBufferStart)
                     *  {
                     * pCurrentBuffer = '*';
                     *      pCurrentBuffer--;
                     *  }
                     * }*/
                }
            }

            dh.StoptWatch();
            templateCh = null;
            buffer     = null;
            templateCh = null;
            sizes      = null;
            sizes2     = null;
            if (gchrndInt.IsAllocated)
            {
                gchrndInt.Free();
            }
            if (gchdot.IsAllocated)
            {
                gchdot.Free();
            }
            if (gchendline.IsAllocated)
            {
                gchendline.Free();
            }

            if (gchsizes2.IsAllocated)
            {
                gchsizes2.Free();
            }

            if (gchsizes.IsAllocated)
            {
                gchsizes.Free();
            }

            if (gchbuffers.IsAllocated)
            {
                gchbuffers.Free();
            }

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());


            unsafe bool AddNewLine(int *psize, int *psize2, int *pdic)
            {
                randomIndex = rnd.Next16();
                bool result = false;

                templateLenghtCh = *(psize + randomIndex);
                position        -= templateLenghtCh;
                while (position >= minStrLength)
                {
                    Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position, templateLenghtCh);
                    result = true;
                    if (rnd.NextBool())
                    {
                        templateLenghtCh = *(psize + randomIndex);
                        position        -= templateLenghtCh;
                    }
                    else
                    {
                        break;
                    }
                }
                return(result);
            }

            bool AddEndLine()
            {
                if (position > 3)
                {
                    position -= 2;
                    Buffer.BlockCopy(endline, 0, buffer, position, 2);
                    return(true);
                }

                return(false);
            }

            bool AddNumber()
            {
                int rndNumber = rnd.Next16();

                byte[] strNumber = RandomBytesProducer.byteList[rndNumber];
                int    length    = RandomBytesProducer.byteListSizes[rndNumber];

                if (position > length)
                {
                    position -= 1;
                    Buffer.BlockCopy(dot, 0, buffer, position, 1);
                    position -= length;
                    Buffer.BlockCopy(strNumber, 0, buffer, position, length);

                    return(true);
                }

                return(false);
            }
        }

        /*
         * {
         *  int maxLengthCh = 512 * 1024 * 1024;
         *  int maxLengthCh2 = maxLengthCh << 1;
         *  Console.WriteLine("Test Bytes Generator :");
         *  char[] buffer = new char[maxLengthCh];
         *
         *  string[] templateCh = new string [10]
         *      {
         *          " apple"
         *          , " town"
         *          , " array"
         *          , " summer"
         *          , " winter"
         *          , " april"
         *          , " customer"
         *          , " support"
         *          , " laptop"
         *          , " cross-domain"
         *      };
         *  RandomIteratorUsafeXorshiftEn randomIteratorUsafeXorshiftEn = new RandomIteratorUsafeXorshiftEn(1024 * 1024);
         *  RandomBytesProducer.InitBytes();
         *
         *  int n = templateCh.Length;
         *  //GCHandle gchLines = GCHandle.Alloc(lines, GCHandleType.Pinned);
         *  char*[] pLines = new char*[n];
         *  //GCHandle gchpLines = GCHandle.Alloc(pLines, GCHandleType.Pinned);
         *  IntPtr[] linesPtr = new IntPtr[n];
         *
         *  int[] sizes = new int[n];
         *  GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned);
         *  IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0);
         *  int* pSize = (int*)addrSizes.ToPointer();
         *
         *  int[] sizes2 = new int[n];
         *  GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned);
         *  IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0);
         *  int* pSizes2 = (int*)addrSizes2.ToPointer();
         *
         *  int sizeTmp = 0;
         *  for (int i = 0; i < n; i++)
         *  {
         *      sizeTmp = templateCh[i].Length;
         *      sizes[i] = sizeTmp;
         *      sizes2[i] = sizeTmp << 1;
         *  }
         *  dh.StartWatch();
         *  int position = maxLengthCh;
         *  int position2 = maxLengthCh << 2;
         *  int templateLenghtCh = templateCh.Length;
         *  int templateLenghtCh2 = templateCh.Length << 1;
         *  int randomIndex = 0;
         *  n--;//--
         *  for (int i = 0; i < 200; i++)
         *  {
         *      randomIndex = n;//--rnd1.Next(n);
         *      templateLenghtCh = *(pSize + randomIndex);
         *      //
         *      templateLenghtCh2 = *(pSizes2 + randomIndex);
         *      //position = maxLengthCh - templateLenghtCh;
         *      position2 = maxLengthCh2 - templateLenghtCh2;
         *      while (position2 >= 0)
         *      {
         *          Buffer.BlockCopy(templateCh[randomIndex], 0, buffer, position2, templateLenghtCh2);
         *          //Buffer.MemoryCopy(pLines[randomIndex], pCurrentBuffer, templateLenghtCh2, templateLenghtCh2);
         *          //--randomIndex = rnd1.Next(n);
         *          templateLenghtCh2 = *(pSizes2 + randomIndex);
         *          //templateLenghtCh = *(pSize + randomIndex);
         *          position2 -= templateLenghtCh2;
         *          //position -= templateLenghtCh;
         *          //pCurrentBuffer = pCurrentBuffer - templateLenghtCh;
         *      }
         *      //if(position2 < 0)
         *      //{
         *      //    pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ;
         *      //    while(pCurrentBuffer >= pBufferStart)
         *      //    {
         *      //        *pCurrentBuffer = '*';
         *      //        pCurrentBuffer--;
         *      //    }
         *      //}
         *  }
         *  dh.StoptWatch();
         *  templateCh = null;
         *  buffer = null;
         *  templateCh = null;
         *  sizes = null;
         *  sizes2 = null;
         *  if (gchsizes2.IsAllocated)
         *  {
         *      gchsizes2.Free();
         *  }
         *
         *  if (gchsizes.IsAllocated)
         *  {
         *      gchsizes.Free();
         *  }
         *  GarbachCollectorHelper.GBForceRun();
         *  Console.WriteLine(dh.GetMessage());
         * }*/
    }
예제 #13
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();
        }
        public static void TestRandomIteratorUsafeXorshift()
        {
            int randomValue = 0;


            Console.WriteLine("Test Random generator Iterator Unsafe Xor Shift En Pointer: ");
            dh.StartWatch();
            RandomIteratorUsafeXorshiftEn randomIteratorUsafeEn = new RandomIteratorUsafeXorshiftEn(1024 * 1024);
            ulong n = (ulong)20 * (ulong)1024 * (ulong)1024 * (ulong)1024;

            for (ulong i = n; i != 0; i--)
            {
                randomValue = randomIteratorUsafeEn.bNextPointer();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Test Random generator Iterator Unsafe Xor Shift En: ");
            dh.StartWatch();
            RandomIteratorUsafeXorshift randomIteratorUnsafe = new RandomIteratorUsafeXorshift(1024 * 1024);

            n = (ulong)20 * (ulong)1024 * (ulong)1024 * (ulong)1024;
            for (ulong i = n; i != 0; i--)
            {
                randomValue = randomIteratorUnsafe.bNext();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Test Random generator Iterator Unsafe Xor Shift En: ");
            randomIteratorUsafeEn = new RandomIteratorUsafeXorshiftEn(1024 * 1024);
            n = (ulong)1024 * (ulong)1024 * (ulong)1024 * (ulong)1024;

            Console.WriteLine("i++");
            dh.StartWatch();

            for (ulong i = 0; i < n; i++)
            {
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("--i");
            dh.StartWatch();

            for (ulong i = n; i != 0; --i)
            {
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("i--");
            dh.StartWatch();

            for (ulong i = n; i != 0; i--)
            {
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("++i");
            dh.StartWatch();


            for (ulong i = 0; i < n; ++i)
            {
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }