Algs4-1.4DoublingRatio

图片
 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 timer=new Stopwatch();
        int cnt=ThreeSum.count(a);
        return timer.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  ",N,time);
           StdOut.printf("%5.1f\n",time/prev);
           prev=time;
       }
    }
}
posted @ 2018-10-26 08:54  修电脑的龙生  阅读(131)  评论(0编辑  收藏  举报