content: /*************************************************************************
   *  Compilation:  javac DoublingRatio.java
   *  Execution:    java DoublingRatio
   *  Dependencies: ThreeSum.java Stopwatch.java StdRandom.java StdOut.java
   *
   *
   *  % java DoublingTest 
   *      512 6.48
   *     1024 8.30
   *     2048 7.75
   *     4096 8.00
   *     8192 8.05
   *   ... 
   *
   *************************************************************************/
  
  public class DoublingRatio {
  
      public static double timeTrial(int N) {
          int MAX = 1000000;
          int[] a = new int[N];
          for (int i = 0; i < N; i++) {
              a[i] = StdRandom.uniform(-MAX, MAX);
          }
          Stopwatch s = new Stopwatch();
          int cnt = ThreeSum.count(a);
          return s.elapsedTime();
      }
  
  
      public static void main(String[] args) { 
          double prev = timeTrial(125);
          for (int N = 250; true; N += N) {
              double time = timeTrial(N);
              StdOut.printf("%6d %7.1f %5.1f\n", N, time, time/prev);
              prev = time;
          } 
      } 
  } 
  
  