Beispiel #1
0
        //
        //
        //
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine(String.Format("MultipleKeys.Multi.sample, {0}", (IntPtr.Size == 4) ? "32 bit" : "64 bit"));
            Console.WriteLine("----------------------------------");

            int max = 36000;

            string[] aCity     = { "London", "Moscow", "Warsaw", "Berlin", "Paris", "Prague", "Brussels", "Vienna", "Zagreb", "Helsinki" };
            int      iPocetAdd = 0;
            Random   r         = new Random((int)DateTime.Now.Ticks);

            uint[] aRand       = new uint[max];
            var    hashSetRand = new HashSet <uint>();

            while (iPocetAdd < max)
            {
                uint rand = (uint)r.Next(0, Int32.MaxValue - 1);
                if (hashSetRand.Contains(rand) == false)
                {
                    hashSetRand.Add(rand);
                    aRand[iPocetAdd] = rand;
                    iPocetAdd++;
                }
            }
            hashSetRand = null;
            long iMem = GC.GetTotalMemory(true);

            Console.WriteLine("UsedMemory {0,4} MB", iMem >> 20);
            long iMemOld = iMem;

            //
            //
            iPocetAdd = 0;
            Console.WriteLine("----------------------------------");
            Console.WriteLine("FcsFastBTreeN");
            TestKV btnTest = new TestKV();
            var    swFcsKV = Stopwatch.StartNew();

            for (int iter = 0; iter < 100; iter++)
            {
                for (int idx = 0; idx < max; idx++)
                {
                    BtnKey key;
                    key.keyCity = aCity[idx % aCity.Length];
                    key.keyId   = idx % 1200;
                    BtnValue value;
                    value.count = 1;
                    if (idx % 50 == 12)
                    {
                        value.aRand = null;
                    }
                    else
                    {
                        value.aRand    = new uint[1];
                        value.aRand[0] = aRand[idx];
                    }
                    if (idx % 60 == 12)
                    {
                        value.aDateTime = null;
                    }
                    else
                    {
                        value.aDateTime    = new DateTime[1];
                        value.aDateTime[0] = DateTime.Now;
                    }
                    if (btnTest.BtnAdd(key, ref value, null) != null)
                    {
                        iPocetAdd++;
                    }
                }
            }
            swFcsKV.Stop();
            iMem = GC.GetTotalMemory(true);
            Console.WriteLine("UsedMemory {0,5} MB [{1,5:N1} s] | {3} keys | Δ {2,3} MB | {4,8:N0} ns   | {5,10:N0} values", iMem >> 20, swFcsKV.Elapsed.TotalSeconds, (iMem - iMemOld) >> 20,
                              btnTest.BtnUsedKeys(), ((double)(swFcsKV.Elapsed.TotalMilliseconds * 1000000) / iPocetAdd), btnTest.BtnUsedValues());
            iMemOld = iMem;
            int iCompareCount = 0;

            swFcsKV.Restart();
            foreach (KeyValuePair <BtnKey, BtnValue>?value in btnTest)
            {
                iCompareCount++;
            }
            swFcsKV.Stop();
            Console.WriteLine("\nFcsFastBTreeN - foreach()");
            Console.WriteLine($"{((double)(swFcsKV.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),9:N2} ns  [{swFcsKV.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} keys ]{iCompareCount / swFcsKV.Elapsed.TotalSeconds,20:N0} IOPS");

            iCompareCount = 0;
            FcsBTreeN <BtnKey, BtnValue> .BtnEnumerator btnEn = btnTest.GetEnumeratorEx(false);
            swFcsKV.Restart();
            while (btnEn.MoveNext())
            {
                KeyValuePair <BtnKey, BtnValue>?value = btnEn.Current;
                iCompareCount++;
            }
            swFcsKV.Stop();
            Console.WriteLine("\nFcsBTreeN - foreach()");
            Console.WriteLine($"{((double)(swFcsKV.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),9:N2} ns  [{swFcsKV.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} keys ]{iCompareCount / swFcsKV.Elapsed.TotalSeconds,20:N0} IOPS");

            iCompareCount = 0;
            swFcsKV.Restart();
            if (btnTest.BtnFastFirst(out BtnKey fcsKey2, out BtnValue fcsValue2, 2) != null)
            {
                iCompareCount++;
                while (btnTest.BtnFastNext(ref fcsKey2, out fcsValue2, 2) != null)
                {
                    iCompareCount++;
                }
            }
            swFcsKV.Stop();
            Console.WriteLine("\nFcsFastBTreeN - BtnFastFirst()/BtnFastNext()");
            Console.WriteLine($"{((double)(swFcsKV.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),9:N2} ns  [{swFcsKV.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} keys ]{iCompareCount / swFcsKV.Elapsed.TotalSeconds,20:N0} IOPS");
            //
            //

            Console.WriteLine("----------------------------------");
            Console.WriteLine("Key ENTER press.");
            Console.ReadLine();
        }