Guest User

Untitled

a guest
Nov 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public static long testOnce(Sort sorter, int size) {
  2.         int[] input = new int[size];
  3.        
  4.         for(int i = 0; i < size; i++) {
  5.             input[i] = (int)((Math.random() * 2 - 1) * Integer.MAX_VALUE);
  6.         }
  7.        
  8.         if(DISPLAY_ARRAYS) {
  9.             System.out.println("Input: " + Arrays.toString(input));
  10.         }
  11.        
  12.         long start = System.nanoTime();
  13.         sorter.sort(input);
  14.         long finish = System.nanoTime();
  15.        
  16.         if(DISPLAY_ARRAYS) {
  17.             System.out.println("Output: " + Arrays.toString(input));
  18.         }
  19.        
  20.         return finish - start;
  21.     }
  22.    
  23.     public static long testSize(Sort sorter, int size) {
  24.         long totalTime = 0;
  25.         for(int i = 0; i < TRIALS; i++) {
  26.             long time = testOnce(sorter, size);
  27.             totalTime += time;
  28.            
  29.             if(DISPLAY_TIMES) {
  30.                 System.out.println("Time (ns): " + time);
  31.             }
  32.         }
  33.         return totalTime / TRIALS;
  34.     }
Add Comment
Please, Sign In to add comment