public void measure() { Console.WriteLine("\n\n\t\tBUBBLE SORT PERFORMANCE TESTING!\n\n"); Random r = new Random(); SearchingAndSorting sas = new SearchingAndSorting(); double totalComps = 0; int compsThisTime = 0; double totalSwaps = 0; int swapsThisTime = 0; for (int i = 1; i < 5; i++) { int arraySize = i * i * 100; totalComps = 0; // repeat 1000 times: create an unsorted array, and sort it. int numTimes = 2; for (int j = 0; j < numTimes; j++) { int[] nums = new int[arraySize]; for (int k = 0; k < arraySize; k++) { // give each element a random starting value. nums[k] = r.Next(arraySize); } sas.BubbleSortPerfMeasured(nums, out swapsThisTime, out compsThisTime); totalComps += compsThisTime; totalSwaps += swapsThisTime; } Console.WriteLine("For an array of " + arraySize + " elements, there were an average of " + totalComps / numTimes + " comparisons performed, and an average of " + totalSwaps / numTimes + "swaps performed"); } }
public void RunExercise() { SearchingAndSorting ase = new SearchingAndSorting(); int[] i = { 10, 1, 12, 3, 9, 32, 36 }; // int test = 32; int comparison = 0; int swaps = 0; //if (ase.FindIntegerLinearPerfMeasured(test, i,out comparison) == false) // Console.WriteLine("Not, after {0} comparisons",comparison); //if (ase.FindIntegerLinearPerfMeasured(test, i,out comparison) == true) // Console.WriteLine("Is in, after {0} comparisons",comparison); // ase.FindIntegerBinaryPerfMeasured(test, i, out comparison); // ase.BubbleSort(i); ase.BubbleSortPerfMeasured(i, out swaps, out comparison); }