示例#1
0
        public static void TestAccesToVariables(int n = Int32.MaxValue, int iteration = 100)
        {
            byte tmp = 0;

            byte[] internalArray = new byte[n];

            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Access to internal array ");
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    tmp = internalArray[i];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            internalArray = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            byte[] externalArray = new byte[n];

            Console.WriteLine("Access to external array ");
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    tmp = externalArray[i];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            externalArray = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Access to class array ");
            testClass.classArray = new byte[n];
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    tmp = testClass.classArray[i];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            testClass.classArray = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Access to prop array ");
            propArray = new byte[n];
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    tmp = propArray[i];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            testClass.classArray = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Access to inline array ");
            inlineArray = new byte[n];
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    tmp = inlineArray[i];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            testClass.classArray = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        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());
         * }*/
    }
示例#4
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();
        }
示例#5
0
        public static void TestListVsArray(int n = Int32.MaxValue, int iteration = 100)
        {
            byte tmp = 0;

            byte[] arrayTest = new byte[n];

            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Fill array : ");
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    arrayTest[i] = tmp;
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            arrayTest = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            List <byte> list = new List <byte>();

            Console.WriteLine("Fill list add ");
            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    list.Add(tmp);
                }
                list.Clear();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            list = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Fill list capasity ");
            List <byte> listCapasity = new List <byte>(n);

            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    listCapasity.Add(tmp);
                }
                listCapasity.Clear();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            listCapasity = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());



            Console.WriteLine("Fill list capasity [] ");
            List <byte> listCapasityIndex = new List <byte>(n);

            dh.StartWatch();
            for (int j = 0; j < iteration; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    listCapasityIndex[i] = (tmp);
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            listCapasityIndex = null;
            Console.WriteLine("GB ");
            dh.StartWatch();
            GarbachCollectorHelper.GBForceRun();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
示例#6
0
        unsafe public static void IterateArray(int n = 1024 *1024, int iteration = 100 *1024)
        {
            Console.WriteLine("----------------------------------------------------------");

            int value = 0;

            byte[] array = null;
            int    n1    = n;

            n1--;
            Console.WriteLine("Generate array");
            dh.StartWatch();
            array = new byte[n];
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Iterate array foreach ");

            dh.StartWatch();
            for (int j = iteration; j != 0; j--)
            {
                foreach (int i in array)
                {
                    value = i;
                }
            }
            dh.StoptWatch();
            array = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array = new byte[n];
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Iterate array for (i++)");

            dh.StartWatch();
            for (int j = iteration; j != 0; j--)
            {
                for (int i = 0; i < n; i++)
                {
                    value = array[i];
                }
            }
            dh.StoptWatch();
            array = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array = new byte[n];
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Iterate array for (++i)");

            dh.StartWatch();
            for (int j = iteration; j != 0; j--)
            {
                for (int i = 0; i < n; ++i)
                {
                    value = array[i];
                }
            }
            dh.StoptWatch();
            array = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());


            Console.WriteLine("Generate array");
            dh.StartWatch();
            array = new byte[n];
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Iterate array for (i--)");

            dh.StartWatch();
            for (int j = iteration; j != 0; j--)
            {
                for (int i = n - 1; i >= 0; i--)
                {
                    value = array[i];
                }
            }
            dh.StoptWatch();
            array = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array = new byte[n];
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
            Console.WriteLine("Iterate array for (--i)");

            dh.StartWatch();
            for (int j = iteration; j != 0; j--)
            {
                for (int i = n - 1; i >= 0; --i)
                {
                    value = array[i];
                }
            }
            dh.StoptWatch();
            array = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array        = new byte[n];
            array[n - 1] = 1;
            array[n - 2] = 2;
            array[0]     = 255;
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Iterate array by pointer < --i");
            dh.StartWatch();
            fixed(byte *start = &array[0])
            {
                for (int j = iteration; j != 0; j--)
                {
                    byte *end = start + n;

                    do
                    {
                        value = *(--end);
                    }while (start < end);
                }
            }

            dh.StoptWatch();
            array = null;

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

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array        = new byte[n];
            array[n - 1] = 1;
            array[n - 2] = 2;
            array[0]     = 255;
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Iterate array by pointer <= --i");
            dh.StartWatch();
            fixed(byte *start = &array[0])
            {
                for (int j = iteration; j != 0; j--)
                {
                    byte *end = start + n;
                    --end;
                    do
                    {
                        value = *(end);
                        --end;
                    }while (start <= end);
                }
            }

            dh.StoptWatch();
            array = null;

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

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array        = new byte[n];
            array[n - 1] = 1;
            array[n - 2] = 2;
            array[0]     = 255;
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Iterate array by pointer < i--");
            dh.StartWatch();
            fixed(byte *start = &array[0])
            {
                for (int j = iteration; j != 0; j--)
                {
                    byte *end = start + n;

                    do
                    {
                        end--;
                        value = *(end);
                    }while (start < end);
                }
            }

            dh.StoptWatch();
            array = null;

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

            Console.WriteLine("Generate array");
            dh.StartWatch();
            array        = new byte[n];
            array[n - 1] = 1;
            array[n - 2] = 2;
            array[0]     = 255;
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Iterate array by pointer <= i--");
            dh.StartWatch();
            fixed(byte *start = &array[0])
            {
                for (int j = iteration; j != 0; j--)
                {
                    byte *end = start + n;
                    end--;
                    do
                    {
                        value = *(end);
                        end--;
                    }while (start <= end);
                }
            }

            dh.StoptWatch();
            array = null;

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        unsafe public static void TestArrayWithDictionaryPinnedArrayFaterRandomIterator(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200)
        {
            int maxLengthCh2 = (int)maxLengthCh << 1;

            Console.WriteLine("Test char array with dictionary and faster random iterator :");
            char[] buffer = new char[maxLengthCh];
            RandomIteratorUsafeXorshift rnd = new RandomIteratorUsafeXorshift(256);
            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);

            char[][] templateCh = { " apple".ToCharArray(), " town".ToCharArray(), " array".ToCharArray(), " summer".ToCharArray(), " winter".ToCharArray(), " april".ToCharArray(), " customer".ToCharArray(), " support".ToCharArray(), " laptop".ToCharArray(), " cross-domain".ToCharArray() };

            int n = templateCh.Length;

            //GCHandle.Alloc(templateCh, GCHandleType.Pinned);
            GCHandle[] lines = new GCHandle[n];
            //GCHandle gchLines = GCHandle.Alloc(lines, GCHandleType.Pinned);
            char *[] pLines = new char *[n];
            //GCHandle gchpLines = GCHandle.Alloc(pLines, GCHandleType.Pinned);
            IntPtr[] linesPtr = new IntPtr[n];
            //GCHandle gchlinesPtr = GCHandle.Alloc(linesPtr, GCHandleType.Pinned);
            for (int i = 0; i < n; i++)
            {
                lines[i]    = GCHandle.Alloc(templateCh[i], GCHandleType.Pinned);
                linesPtr[i] = Marshal.UnsafeAddrOfPinnedArrayElement(templateCh[i], 0);
                pLines[i]   = (char *)linesPtr[i].ToPointer();
            }
            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 position2         = maxLengthCh << 2;
            int templateLenghtCh  = (int)templateCh.Length;
            int templateLenghtCh2 = (int)templateCh.Length << 1;
            int randomIndex       = 0;

            char[]   endline    = Environment.NewLine.ToCharArray();
            GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned);

            char[] dot = new char[1] {
                '.'
            };
            GCHandle gchdot = GCHandle.Alloc(endline, GCHandleType.Pinned);

            byte[] rndInt = new byte[4] {
                rnd.bNext(), rnd.bNext(), rnd.bNext(), rnd.bNext()
            };
            GCHandle gchrndInt    = GCHandle.Alloc(endline, GCHandleType.Pinned);
            byte     rndIntIndex  = 0;
            int      minStrLength = 0;
            byte     wordCount    = 0;

            fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary)
            {
                for (int i = 0; i < iteration; i++)
                {
                    position2 = maxLengthCh2;


                    //position = maxLengthCh - templateLenghtCh;
                    AddEndLine();
                    while (position2 >= minStrLength)
                    {
                        wordCount = (byte)((rnd.bNext() >> 5));
                        wordCount++;
                        if (AddNewLine(psize, psize2, pdic, wordCount))
                        {
                            AddNumber();
                            AddEndLine();
                        }
                    }

                    /*
                     * 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 (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();/*
                                   * if (gchLines.IsAllocated)
                                   * gchLines.Free();*//*
                                   * if (gchpLines.IsAllocated)
                                   * gchpLines.Free();*//*
                                   * if (gchlinesPtr.IsAllocated)
                                   * gchlinesPtr.Free();*/
            }

            for (int i = 0; i < n; i++)
            {
                if (lines[i].IsAllocated)
                {
                    lines[i].Free();
                }
            }
            GarbachCollectorHelper.GBForceRun();
            //Console.WriteLine(dh.GetMessage());
            return;

            unsafe bool AddNewLine(int *psize, int *psize2, int *pdic, byte count)
            {
                byte counter = 0;

                randomIndex = (rnd.bNext() << 8) + rnd.bNext();//--rnd1.Next(n);
                //

                templateLenghtCh2 = *(psize2 + randomIndex);
                position2        -= templateLenghtCh2;
                while (position2 >= minStrLength)
                {
                    Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position2, templateLenghtCh2);
                    counter++;
                    if (counter >= count)
                    {
                        return(true);
                    }
                    else
                    {
                        templateLenghtCh2 = *(psize2 + randomIndex);
                        position2        -= templateLenghtCh2;
                    }
                }
                return(false);
            }

            bool AddEndLine()
            {
                if (position2 > 6)
                {
                    position2 -= 4;
                    Buffer.BlockCopy(endline, 0, buffer, position2, 4);
                    return(true);
                }

                return(false);
            }

            /*
             * bool AddNumber()
             * {
             *  uint rndNumber = BitConverter.ToUInt32(rndInt, 0);
             *  if (rndNumber == 0)
             *  {
             *      rndNumber++;
             *  }
             *  byte shift = rnd.bNext();
             *  rndInt[rndIntIndex] = shift;
             *  rndIntIndex++;
             *  if(rndIntIndex>=4)
             *  {
             *      rndIntIndex = 0;
             *  }
             *  for(int i = 0; i < 4; i++)
             *  {
             *      rndInt[i] = (byte) (rndInt[i] & shift);
             *  }
             *  char[] strNumber = rndNumber.ToString().ToCharArray();
             *  int length2 = strNumber.Length << 1;
             *  if (position2 > length2)
             *  {
             *      position2 -= 2;
             *      Buffer.BlockCopy(dot, 0, buffer, position2, 2);
             *      position2 -= length2;
             *      Buffer.BlockCopy(strNumber, 0, buffer, position2, length2);
             *
             *      return true;
             *  }
             *
             *  return false;
             * }
             */

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

                ;
                char[] strNumber = rndNumber.ToString().ToCharArray();
                int    length2   = strNumber.Length << 1;

                if (position2 > length2)
                {
                    position2 -= 2;
                    Buffer.BlockCopy(dot, 0, buffer, position2, 2);
                    position2 -= length2;
                    Buffer.BlockCopy(strNumber, 0, buffer, position2, length2);

                    return(true);
                }

                return(false);
            }
        }
    }