public class SortPerformance { public static void main (String[] argv) { int size = 10000; int[] A = makeRandomArray (size); long startTime = System.currentTimeMillis (); selectionSort (A); long timeTaken = System.currentTimeMillis () - startTime; System.out.println ("Selection sort time: " + timeTaken); // Create a fresh array. A = makeRandomArray (size); // Quicksort algorithm. startTime = System.currentTimeMillis (); quickSort (A); timeTaken = System.currentTimeMillis () - startTime; System.out.println ("Quicksort's time: " + timeTaken); } static void selectionSort (int[] A) { // We don't need to find the n-th smallest, so stop at n-1. for (int i=0; i=left; i--) { // Examine everything between left and right-1 inclusive. if (data[i] > partitionElement) { // Switch with swap position currentSwapPosition--; swap (data, currentSwapPosition, i); // Shift swap position rightwards: } } // Last one: swap (data, currentSwapPosition, right); return currentSwapPosition; } static void swap (int[] data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } static int[] makeRandomArray (int length) { int[] A = new int [length]; for (int i=0; i