Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long testOnce(Sort sorter, int size) {
- int[] input = new int[size];
- for(int i = 0; i < size; i++) {
- input[i] = (int)((Math.random() * 2 - 1) * Integer.MAX_VALUE);
- }
- if(DISPLAY_ARRAYS) {
- System.out.println("Input: " + Arrays.toString(input));
- }
- long start = System.nanoTime();
- sorter.sort(input);
- long finish = System.nanoTime();
- if(DISPLAY_ARRAYS) {
- System.out.println("Output: " + Arrays.toString(input));
- }
- return finish - start;
- }
- public static long testSize(Sort sorter, int size) {
- long totalTime = 0;
- for(int i = 0; i < TRIALS; i++) {
- long time = testOnce(sorter, size);
- totalTime += time;
- if(DISPLAY_TIMES) {
- System.out.println("Time (ns): " + time);
- }
- }
- return totalTime / TRIALS;
- }
Add Comment
Please, Sign In to add comment