The Java API Calendar class contains a method called getTimeInMillisec which enables you to retrieve the absolute time (in milliseconds) at which any Calendar object was created. As indicated in Section 8.12, you can get such an object by calling the getInstance class method. You can use this capability to evaluate the runtime of any chunk of code. All you have to do is create a Calendar object before the test code starts, create another Calendar object right after the code ends, and print out the difference in those two object’s times. To demonstrate this capability, write a short program called
Test Runtime that asks the user for a desired number of iterations, num. Then have it measure the runtime for a loop of num iterations that executes the single statement:
Math.cos(0.01 * i);
The variable i is the loop count variable.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.