public static void TestRandomGeneratorIteratorUnsafe()
        {
            int randomValue = 0;

            Console.WriteLine("Test Random generator Iterator Unsafe En: ");
            dh.StartWatch();
            RandomIteratorUsafeEn randomIteratorUsafeEn = new RandomIteratorUsafeEn(16, 1, 10);

            for (long i = 20000000000; i != 0; --i)
            {
                randomValue = randomIteratorUsafeEn.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Test Random generator Iterator Unsafe: ");
            dh.StartWatch();
            RandomIteratorUsafe randomIteratorUnsafe = new RandomIteratorUsafe(100000, 1, 10);

            for (long i = 0; i < 20000000000; i++)
            {
                randomValue = randomIteratorUnsafe.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestStringBuilder()
        {
            int           maxLength = 256 * 1024 * 1024;
            StringBuilder sb        = new StringBuilder(maxLength, maxLength);

            Console.WriteLine("Test StringBuilder :");
            string templateSB  = "1234567812345678";
            string templateTmp = "";

            dh.StartWatch();
            for (int i = 0; i < 400; i++)
            {
                while (sb.Length < maxLength)
                {
                    sb.Append(templateSB);
                }
                templateTmp = sb.ToString();
                templateTmp = "";
                sb.Clear();
            }
            sb = null;
            dh.StoptWatch();

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestChaArrayUseLength()
        {
            Random rnd         = new Random();
            int    maxLengthCh = 512 * 1024 * 1024;

            Console.WriteLine("Test char array (length):");
            char[] buffer     = new char[maxLengthCh];
            char[] templateCh = new char[16] {
                '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8'
            };
            dh.StartWatch();
            int position = maxLengthCh;

            for (int i = 0; i < 200; i++)
            {
                position = maxLengthCh - templateCh.Length;
                while (position >= 0)
                {
                    rnd.Next(10);
                    Buffer.BlockCopy(templateCh, 0, buffer, position << 1, templateCh.Length << 1);
                    position -= templateCh.Length;
                }
            }
            dh.StoptWatch();
            templateCh = null;
            buffer     = null;

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestStringBuilderWithCharArray()
        {
            Random        rnd       = new Random();
            int           maxLength = 256 * 1024 * 1024;
            StringBuilder sb        = new StringBuilder(maxLength, maxLength);

            Console.WriteLine("Test stringBuilder char array :");
            char[] templateCh = new char[16] {
                '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8'
            };
            string templateTmp = "";

            dh.StartWatch();
            for (int i = 0; i < 400; i++)
            {
                while (sb.Length < maxLength)
                {
                    rnd.Next(10);
                    sb.Append(templateCh);
                }
                templateTmp = sb.ToString();
                templateTmp = "";
                sb.Clear();
            }
            sb = null;
            dh.StoptWatch();

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
Beispiel #5
0
        public static void TestArrayWithDictionaryUseLength()
        {
            int maxLengthCh  = 512 * 1024 * 1024;
            int maxLengthCh2 = maxLengthCh << 1;

            Console.WriteLine("Test char array with dictionary (length):");
            char[]   buffer     = new char[maxLengthCh];
            char[][] templateCh = { " apple".ToCharArray(), " town".ToCharArray(), " array".ToCharArray(), " summer".ToCharArray(), " winter".ToCharArray(), " aplril".ToCharArray(), " customer".ToCharArray(), " support".ToCharArray(), " laptop".ToCharArray(), " cross-domain".ToCharArray() };
            int      n          = templateCh.Length;

            int[] sizes   = new int[n];
            int[] sizes2  = new int[n];
            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    templateLenghtCh2 = templateCh.Length << 1;
            int    randomIndex       = 0;
            Random rnd1 = new Random();

            char[] tmpChArray = null;
            n--;
            for (int i = 0; i < 200; i++)
            {
                randomIndex = n;// rnd1.Next(n);

                tmpChArray        = templateCh[randomIndex];
                templateLenghtCh2 = tmpChArray.Length << 1;

                position2 = maxLengthCh2 - templateLenghtCh2;
                while (position2 >= 0)
                {
                    Buffer.BlockCopy(tmpChArray, 0, buffer, position2, templateLenghtCh2);
                    //randomIndex = rnd1.Next(n);
                    tmpChArray        = templateCh[randomIndex];
                    templateLenghtCh2 = tmpChArray.Length << 1;
                    position2        -= templateLenghtCh2;
                }
            }

            dh.StoptWatch();
            templateCh = null;
            buffer     = null;
            templateCh = null;
            sizes      = null;
            sizes2     = null;
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestArrayCopyBlockCopy(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 = 0;
                //index = rnd.bNext();
                index = 1;
                while (position + index < n)
                {
                    Buffer.BlockCopy(sourceArra, 0, destArray, position, index);
                    index     = rnd.bNext();
                    position += index;
                }
            }

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

            destArray = null;
            GarbachCollectorHelper.GBForceRun();
        }
Beispiel #7
0
        public static void Test2(int n = Int32.MaxValue)
        {
            Console.WriteLine("--------------------------------------------- ");
            Int64 result = 0;

            Console.WriteLine(n);
            Console.WriteLine("Multiplay 2 ");
            dh.StartWatch();
            for (int i = 0; i <= n; i++)
            {
                result = i * 2;
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Subtract 2 ");
            dh.StartWatch();
            for (int i = 0; i <= n; i++)
            {
                result = i / 2;
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("<< 2 ");
            dh.StartWatch();
            for (int i = 0; i <= n; i++)
            {
                result = i << 1;
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine(">> 2 ");
            dh.StartWatch();
            for (int i = 0; i <= n; i++)
            {
                result = i >> 1;
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestArrayCopyIndexing(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;

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

            dh.StartWatch();

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

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

            destArray = null;
            GarbachCollectorHelper.GBForceRun();
        }
Beispiel #9
0
        public static void TestRandom()
        {
            Random rnd = new Random();

            Console.WriteLine("Test Random generator : ");
            dh.StartWatch();
            for (long i = 0; i < 20000000000; i++)
            {
                rnd.Next(1, 10);
            }
            dh.StoptWatch();
            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
Beispiel #10
0
        public static void TestGetLength()
        {
            Console.WriteLine("Test get length: ");
            int length = 0;

            dh.StartWatch();
            for (long i = 0; i < 20000000000; i++)
            {
                length = "fffff".Length;
            }
            dh.StoptWatch();

            Console.WriteLine(dh.GetMessage());
        }
        public static void TestRandomGeneratorRndXorshift()
        {
            int randomValue = 0;

            Console.WriteLine("Test Random generator RndXorshift bool: ");

            XorshiftUnrolled64 rndXorshift = new XorshiftUnrolled64();

            byte[]   buffer        = new byte[1024 * 1024];
            char[]   bufferChar    = new char[1024 * 1024];
            GCHandle gchBuffer     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            GCHandle gchBufferChar = GCHandle.Alloc(bufferChar, GCHandleType.Pinned);
            IntPtr   pAddr         = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
            IntPtr   pAddrChar     = Marshal.UnsafeAddrOfPinnedArrayElement(bufferChar, 0);

            dh.StartWatch();
            unsafe
            {
                //fixed (byte* pStart = buffer)
                {
                    byte * pStart   = (byte *)pAddr.ToPointer();
                    byte * pEnd     = pStart + buffer.Length;
                    ulong *plStart  = (ulong *)pStart;
                    ulong *plEnd    = (ulong *)pEnd;
                    byte * pCurrent = pStart;
                    for (int i = 0; i < 20000; i++)
                    {
                        pCurrent = pStart;
                        //rndXorshift.NextBytes(buffer);
                        rndXorshift.FillBufferEx(plStart, plEnd);

                        /*
                         * while (pCurrent <= pEnd)
                         * {
                         *  //randomValue = *pCurrent & 100000;
                         *  randomValue = *pCurrent;
                         *  pCurrent++;
                         * }
                         */
                    }
                }
            }
            dh.StoptWatch();
            if (gchBuffer.IsAllocated)
            {
                gchBuffer.Free();
            }

            Console.WriteLine(dh.GetMessage());
        }
Beispiel #12
0
        public static void TestRandomGeneratorIterator()
        {
            int randomValue = 0;

            Console.WriteLine("Test Random generator Iterator: ");
            dh.StartWatch();
            RandomIterator randomIterator = new RandomIterator(10000, 1, 10);

            for (long i = 0; i < 20000000000; i++)
            {
                randomValue = randomIterator.Next();
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestRandomGeneratorFastRandom()
        {
            byte[] randomValue = null;
            Console.WriteLine("Test Random generator Fast Random: ");
            dh.StartWatch();
            FastRandom fastRandom = new FastRandom();
            ulong      n          = (ulong)1024 * (ulong)1024 * (ulong)1024;

            for (ulong i = 0; i < n; i++)
            {
                randomValue = Encoding.ASCII.GetBytes(fastRandom.NextInt().ToString());
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        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();
        }
        public static void TestIterateStringLength()
        {
            Console.WriteLine("Test iterate string length: ");
            char   tmp      = ' ';
            string template = "1234567890";

            dh.StartWatch();
            for (long i = 0; i < 20000000000; i++)
            {
                for (int j = 0; j < template.Length; j++)
                {
                    tmp = template[j];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        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());
        }
Beispiel #17
0
        public static void TestIterateCharArrayLength()
        {
            Console.WriteLine("Test iterate char array length: ");
            char tmpChar = ' ';

            char[] templateChar = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
            dh.StartWatch();
            for (long i = 0; i < 20000000000; i++)
            {
                for (int j = 0; j < templateChar.Length; j++)
                {
                    tmpChar = templateChar[j];
                }
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
Beispiel #18
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();
        }
        public static void TestArrayWithDictionaryPinnedArrayFaterRandomIteratorTask()
        {
            ThreadPool.SetMaxThreads(1024, 1024);
            Console.WriteLine("Test TestArrayWithDictionaryPinnedArrayFaterRandomIteratorTask in tasks :");
            dh.StartWatch();
            var t = Task.Run(
                async() =>
            {
                List <Task> tasks = new List <Task>();
                for (int i = 0; i < 1024; i++)
                {
                    tasks.Add(
                        Task.Factory.StartNew(() => { TestArrayWithDictionaryPinnedArrayFaterRandomIterator(1024 * 1024, 100); })
                        );
                }
                await Task.WhenAll(tasks);
            });

            t.Wait();
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        public static void TestCharArrayCopyExtensions()
        {
            Random rnd          = new Random();
            int    maxLengthCh  = 512 * 1024 * 1024;
            int    maxLengthCh2 = maxLengthCh << 1;

            Console.WriteLine("Test char array CopyExtensions:");
            char[] buffer = new char[maxLengthCh];

            char[] templateCh = new char[16] {
                '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8'
            };
            dh.StartWatch();

            {
                int position         = maxLengthCh;
                int position2        = maxLengthCh << 2;
                int templateLenghtCh = templateCh.Length;
                for (int i = 0; i < 200; i++)
                {
                    position = maxLengthCh - templateLenghtCh;
                    while (position >= 0)
                    {
                        rnd.Next(10);
                        CopyExtensions.CopyMemoryCh(templateCh, 0, buffer, position, templateLenghtCh);
                        //Buffer.BlockCopy(templateCh, 0, buffer, position2, templateLenghtCh);
                        position -= templateLenghtCh;
                    }
                }
            }
            dh.StoptWatch();
            templateCh = null;
            buffer     = null;

            GarbachCollectorHelper.GBForceRun();
            Console.WriteLine(dh.GetMessage());
        }
        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());
        }
Beispiel #22
0
        unsafe public static void TestArrayWithDictionaryPinnedArray()
        {
            int maxLengthCh  = 512 * 1024 * 1024;
            int maxLengthCh2 = maxLengthCh << 1;

            Console.WriteLine("Test char array with dictionary :");
            char[] buffer = new char[maxLengthCh];

            GCHandle gchbuffers     = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   addrBuffer     = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 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;
            }
            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;
                pCurrentBuffer = pBuffer - templateLenghtCh + 1;
                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();
            }

            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());
        }
Beispiel #23
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());
        }
        public static void TestRandomGeneratorRndXorshiftByte()
        {
            int randomValue = 0;

            Console.WriteLine("Test RndXorshift generator bytes: ");
            dh.StartWatch();
            XorshiftUnrolled64 rndXorshift = new XorshiftUnrolled64();

            byte[] buffer = new byte[1024 * 1024];
            //GCHandle gchBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            for (int i = 0; i < 20000; i++)
            {
                rndXorshift.NextBytes(buffer);

                /*
                 * foreach (var value in buffer)
                 * {
                 *  randomValue = value;
                 * }
                 */
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Test Fast Random generator bytes: ");
            dh.StartWatch();
            FastRandom fastRandom = new FastRandom();

            byte[] buffer1 = new byte[1024 * 1024];
            //GCHandle gchBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            for (int i = 0; i < 20000; i++)
            {
                fastRandom.NextBytes(buffer1);

                /*
                 * foreach (var value in buffer)
                 * {
                 *  randomValue = value;
                 * }
                 */
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());

            Console.WriteLine("Test Random generator bytes: ");
            Random random = new Random();

            byte[] buffer2 = new byte[1024 * 1024];
            //GCHandle gchBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            for (int i = 0; i < 20000; i++)
            {
                random.NextBytes(buffer2);

                /*
                 * foreach (var value in buffer)
                 * {
                 *  randomValue = value;
                 * }
                 */
            }
            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());
        }
Beispiel #26
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());
        }
Beispiel #27
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 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());
         * }*/
    }
Beispiel #29
0
        unsafe public static void TestArrayCopyFixed(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();
        }