Esempio n. 1
0
        static void BinaryCounterMedium()
        {
            Console.WriteLine("Binary - Counter - Medium");
            Console.WriteLine("ArraySize;Counter");
            SearchClass sc   = new SearchClass();
            Random      rand = new Random();

            for (long i = 2000000; i <= (long)Math.Pow(2, 28); i += 2000000)
            {
                long min   = long.MaxValue;
                long max   = long.MinValue;
                long total = 0;
                for (int j = 0; j < 12; j++)
                {
                    sc.BinarySearchWithCounter(CreateAndFillArray(i, true), rand.Next(0, 1000));
                    total += sc.counter;
                    if (sc.counter > max)
                    {
                        max = sc.counter;
                    }
                    if (sc.counter < min)
                    {
                        min = sc.counter;
                    }
                }

                Console.WriteLine("{0};{1}", i, (total - (max + min)) / 10);
            }
        }
Esempio n. 2
0
        static void BinaryTimerMedium()
        {
            Console.WriteLine("Binary - Timer - Medium");
            Console.WriteLine("ArraySize;Time[s]");
            SearchClass sc   = new SearchClass();
            Random      rand = new Random();

            for (long i = 2000000; i <= (long)Math.Pow(2, 28); i += 2000000)
            {
                long min   = long.MaxValue;
                long max   = long.MinValue;
                long total = 0;
                for (int j = 0; j < 12; j++)
                {
                    int[] arr   = CreateAndFillArray(i, true);
                    long  start = Stopwatch.GetTimestamp();
                    sc.BinarySearch(arr, rand.Next(0, 1000));
                    long stop       = Stopwatch.GetTimestamp();
                    long difference = stop - start;
                    total += difference;
                    if (difference > max)
                    {
                        max = difference;
                    }
                    if (difference < min)
                    {
                        min = difference;
                    }
                }

                Console.WriteLine("{0};{1}", i, (total - (max + min)) / 10);
            }
        }
Esempio n. 3
0
        static void BinaryCounterPesymistic()
        {
            Console.WriteLine("Binary - Counter - Pesymistic");
            Console.WriteLine("ArraySize;Counter");
            SearchClass sc = new SearchClass();

            for (long i = 2000000; i <= (long)Math.Pow(2, 28); i += 2000000)
            {
                sc.BinarySearchWithCounter(CreateAndFillArray(i, true), 1001);
                Console.WriteLine("{0};{1}", i, sc.counter);
            }
        }
Esempio n. 4
0
        static void BinaryTimerPesymistic()
        {
            Console.WriteLine("Binary - Timer - Pesymistic");
            Console.WriteLine("ArraySize;Time[s]");
            SearchClass sc = new SearchClass();

            for (long i = 2000000; i <= (long)Math.Pow(2, 28); i += 2000000)
            {
                int[] arr   = CreateAndFillArray(i, true);
                long  start = Stopwatch.GetTimestamp();
                sc.BinarySearch(arr, 1001);
                long stop = Stopwatch.GetTimestamp();
                Console.WriteLine("{0};{1}", i, (stop - start) * (1.0 / Stopwatch.Frequency));
            }
        }