/**** * * Class ListSortTimes outputs raw data points for worst-case sort of lists * between sizes 100 and 5000, in increments of 100. It uses the method * ListSortAndSearch.sort. *
* The timing graph for the calls to ListSortAndSearch.sort is: *
*
*
* @author Gene Fisher
* @version 17may01
*
*/
public class ListSortTimes {
/**
* Call ListSortAndSearch.sort on lists of sizes 100 through 5000, in
* increments of 100.
*/
public static void main(String[] args) {
/*
* Run the timed test cases.
*/
for (int size = INCREMENT; size <= SIZE; size += INCREMENT) {
generateTime(size);
}
}
/**
* Generate a timing pair for list sorting of the form
*
* list_size sort_time
*/
public static void generateTime(int size) {
ListSortAndSearch sortAndSearch = // Class with the methods
new ListSortAndSearch();
Integer[] list; // Testing list
int i,j; // Loop index
long startTime, endTime; // Timing variables
Integer lastValue; // Last value in sorted list
/*
* Fill up the test list with some unsorted values.
*/
list = new Integer[size];
for (i = size, j = 0; i > 0; i--, j++) {
list[j] = new Integer(i);
}
/*
* Time the sort method.
*/
startTime = System.currentTimeMillis();
sortAndSearch.sort(list);
endTime = System.currentTimeMillis();
System.out.println(size + " " + (endTime - startTime));
}
final static int SIZE = 5000; // Max size of test list
final static int INCREMENT = 100; // Output increment
}