Accuracy of Improving Rate Test for Algs4-1.4.39

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.