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"); } }
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"); } }