예제 #1
0
        /// <summary>
        /// Sort and time the time elapse using my Arrayheap.
        /// </summary>
        /// <param name="thestopwatch"></param>
        /// <param name="arrsize"></param>
        static void SortAll(MyStopwatch thestopwatch, int arrsize)
        {
            IPriorityQ <int> q = new MyLittleArrayHeapPriorityQueue <int>();

            int[] arr = new int[arrsize];
            for (int i = 0; i < arr.Length; arr[i] = i + 1, i++)
            {
                ;
            }
            Randomize(arr);
            thestopwatch.Tick();
            for (int i = 0; i < arr.Length; q.Enqueue(arr[i]), i++)
            {
                ;
            }
            for (int i = 0; i < arr.Length; i++)
            {
                int themin = q.RemoveMin();
                if (themin != i + 1)
                {
                    throw new Exception($"Expected: {i+1} but {themin}");
                }
            }
            thestopwatch.Tock();
        }
예제 #2
0
        /// <summary>
        /// 私有构造函数
        /// </summary>
        /// <param name="frmMain"></param>
        private ProductTestFactory(MainForm frmMain)
        {
            this.frmMain = frmMain;
            stopwatch    = new MyStopwatch(frmMain.DisplayStopwatch);

            flow = new ProductionTestFlow(frmMain);
        }
예제 #3
0
        /// <summary>
        /// Sort and time the process using a system sorted set.
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="arrsize"></param>
        static void SortAllUsingSet(MyStopwatch sw, int arrsize)
        {
            SortedSet <int> q = new SortedSet <int>();

            int[] arr = new int[arrsize];
            for (int i = 0; i < arr.Length; arr[i] = i + 1, i++)
            {
                ;
            }
            Randomize(arr);
            sw.Tick();
            for (int i = 0; i < arr.Length; q.Add(arr[i]), i++)
            {
                ;
            }
            for (int i = 0; i < arr.Length; i++)
            {
                int themin = q.Min;
                q.Remove(themin);
                if (themin != i + 1)
                {
                    throw new Exception($"Expected: {i + 1} but {themin}");
                }
            }
            sw.Tock();
        }
 public static void QuickMedianEfficiency(int size, int repetition)
 {
     WriteLine
         ("Testing the speed for looking for median in a ranmized " +
         "double array; using Top K Sort.");
     WriteLine($"Using Sorted set to look for it, array size: " +
               $"{size}, repeat {repetition} times.");
     WriteLine("here is the result of using SortedSet implemened" +
               " using Red Black Tree:");
     {
         MyStopwatch msw = new MyStopwatch();
         for (int i = repetition; --i >= 0;)
         {
             TimedTopKSort(size, size / 2 + 1, msw, false);
         }
         WriteLine("Done! Here is that speed data: ");
         WriteLine($"The average time took is: " +
                   $"{msw.GetAverageTimeElapse()} ms");
         WriteLine($"The standard Deviation is: " +
                   $"{msw.GetStandardDeviation()} ms");
     }
     WriteLine("Here is the Result using Binary Heap: ");
     {
         MyStopwatch msw = new MyStopwatch();
         for (int i = repetition; --i >= 0;)
         {
             TimedTopKSort(size, size / 2 + 1, msw, true);
         }
         WriteLine("Done! Here is that speed data: ");
         WriteLine($"The average time took is: " +
                   $"{msw.GetAverageTimeElapse()} ms");
         WriteLine($"The standard Deviation is: " +
                   $"{msw.GetStandardDeviation()} ms");
     }
 }
예제 #5
0
        private static MyStopwatch stopwatch;         //秒表


        /// <summary>
        /// 私有构造函数
        /// </summary>
        /// <param name="frmMain"></param>
        private ProductionTestFactory(AllForms.FormMain frmMain)
        {
            this.frmMain = frmMain;

            stopwatch = new MyStopwatch(frmMain.DisplayStopwatch);
            flow      = new ProductionTestFlow(frmMain, ProductionInfo.PlanCode,
                                               ProductionInfo.Procedure, ProductionInfo.Station);
        }
예제 #6
0
        public void Stopwatch_HighResolution()
        {
            var c = new VirtualTimeClock();

            var sw = new MyStopwatch(c);

            sw.Start();

            c.Now += 1000;

            Assert.AreEqual(1000, sw.ElapsedTicks);
            Assert.AreEqual(2000, sw.Elapsed.Ticks);
        }
예제 #7
0
        public void RunSolution()
        {
            ChangeMade = false;

            Counter++;
            MyStopwatch.Start();
            List <Cell> resultCells = FindApplicableCells();

            if (ApplyAlgorithmOnCells(resultCells))
            {
                ChangeMade = true;
                ApplyRippleEffects(resultCells);
            }
            MyStopwatch.Stop();
        }
예제 #8
0
        public async void CheckUrl(string url)
        {
            ProccessIsStart = false;
            MyStopwatch.Restart();
            WebRequest  webRequest = WebRequest.Create(url);
            WebResponse response   = await webRequest.GetResponseAsync();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string sizeOfCharters = await reader.ReadToEndAsync();

                UrlSize = $"Size of Your Size Is: {sizeOfCharters.Length.ToString()} Bytes.";
            }
            ProccessIsStart = true;
            MyStopwatch.Stop();
        }
예제 #9
0
        static long measureTime(Action init, Action toMeasure, int repeats = 10, int filterRepeats = 2)
        {
            List <long> times = new List <long>();

            for (int i = 0; i < repeats; i++)
            {
                init.Invoke();
                MyStopwatch sw;
                using (sw = new MyStopwatch()) {
                    toMeasure.Invoke();
                }
                times.Add(sw.ElapsedTicks);
                //Thread.Sleep(1);
            }
            filterTimeMeasurements(times, filterRepeats);
            return((long)times.Average());
        }
예제 #10
0
        public void TestRunTheTest()
        {
            WriteLine("Using my own priority queue: ");
            var mysw = new MyStopwatch();

            SortAll(mysw, 5000000);
            WriteLine($"{mysw.GetAverageTimeElapse()} ms");

            WriteLine("Using the system's SortedSet: ");
            mysw = new MyStopwatch();
            SortAllUsingSet(mysw, 5000000);
            WriteLine($"{mysw.GetAverageTimeElapse()} ms");

            WriteLine("Using the build heap on my PriorityQ: ");
            mysw = new MyStopwatch();
            SortAllBuildHeap(mysw, 5000000);
            WriteLine($"{mysw.GetAverageTimeElapse()} ms");
        }
예제 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="len">
        /// The len of the randomized double array.
        /// </param>
        /// <param name="k">
        /// The number of top K element you want from the list.
        /// </param>
        /// <param name="msw"></param>
        /// <param name="UseMyHeap"></param>
        public static void TimedTopKSort
            (int len, int k, MyStopwatch msw, bool UseMyHeap = true)
        {
            if (k <= 0 || k > len)
            {
                throw new Exception("What in hey is this? ");
            }
            double[] RandomArr = RandomDoubleArray(len);

            msw.Tick();
            double[] sorted = UseMyHeap ?
                              TopKSortDoubleArrayUsingBinaryHeap(RandomArr, k):
                              TopKSortDoubleArrayUsingSortedSet(RandomArr, k);
            msw.Tock();

            // Quick Varify
            for (int i = 1; i < sorted.Length; i++)
            {
                Assert.IsTrue(sorted[i] >= sorted[i - 1]);
            }
        }
예제 #12
0
        private static double measureTime(int size, MatrixMultAlgorithm alg)
        {
            Matrix m1    = Matrix.GenerateRandomMatrix(size);
            Matrix m2    = Matrix.GenerateRandomMatrix(size);
            var    times = new List <long>();

            for (int i = 0; i < 28; i++)
            {
                MyStopwatch sw;
                using (sw = new MyStopwatch())
                {
                    m1.Multiply(m2, alg);
                }
                times.Add(sw.ElapsedTicks);
                Thread.Sleep(1);
            }
            filterTimeMeasurements(times);
            double avgTime = (double)times.Sum() / times.Count;

            return(avgTime);
        }
예제 #13
0
        public void MainTestingEffeciency()
        {
            int size       = (int)(1e5);
            int TestNumber = 100;

            WriteLine("Testing on array with size: " + size);
            WriteLine("The Array will be shuffled: " + TestNumber + " times.");
            {
                WriteLine("Flushing all elements into the queue, no repeating elements. ");
                int[] arr = new int[size];
                for (int i = 0; ++i != size; arr[i - 1] = i)
                {
                    ;
                }
                MyStopwatch mswforQ         = new MyStopwatch();
                MyStopwatch mswforBuildHeap = new MyStopwatch();
                MyStopwatch mswforSortedSet = new MyStopwatch();
                for (int i = 0; i < TestNumber; i++)
                {
                    SortAll(mswforQ, size);
                    SortAllBuildHeap(mswforBuildHeap, size);
                    SortAllUsingSet(mswforSortedSet, size);
                }
                WriteLine("For the PriorityQ by adding: ");
                WriteLine($"On average, it takes: {mswforQ.GetAverageTimeElapse()} ms");
                WriteLine($"The standard deviation is: {mswforQ.GetStandardDeviation()} ms");

                WriteLine("For the PriorityQ with Buildheap; ");
                WriteLine($"On average, it takes: {mswforBuildHeap.GetAverageTimeElapse()} ms");
                WriteLine($"The standard deviation is: {mswforBuildHeap.GetStandardDeviation()} ms");

                WriteLine("For the SortedSet by adding: ");
                WriteLine($"On average, it takes: {mswforSortedSet.GetAverageTimeElapse()} ms");
                WriteLine($"The standard deviation is: {mswforSortedSet.GetStandardDeviation()} ms");
            }
        }