Exemple #1
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);
            }
        }
Exemple #2
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));
            }
        }