1.4.39 improve the accuracy of rate testing. Modify doublingration so that it accepts another command line parameter to specify the number of times the timetrial () method is called for each n value. Use a program to perform experiments 10, 100, and 1000 times per N and evaluate the accuracy of the results.
A:
Public class e1d4d39
{
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 ();
Return timer. elapsedtime ();
}
//
Public static void main (string [] ARGs)
{
//
Double prev= 0.0;
Double time = 0.0;
For (INT I = 10; I <= 1000; I = 10 * I)
{
Prev = 0.0;
For (Int J = 1; j <= I; j ++)
Prev = Prev + timetrial (125 );
//
For (INT n = 250; n <= 8000; n + = N)
{
Time = 0.0;
For (int K = 1; k <= I; k ++)
{
Time = Time + timetrial (N );
} // For K
Stdout. printf ("RunTime = % 5d n = % 6D timesecond = % 7.1f ratio = % 5.1f \ n", I, n, time/I, time/PREV );
Prev = time;
} // For N
} // For I
} // End main
} // End class
Accuracy of Improving Rate Test for Algs4-1.4.39