The Java API
Calendarclass contains a method called
getTimeInMillisecwhich enables you to retrieve the absolute time (in milliseconds) at which any
Calendarobject was created. As indicated in Section 8.15, you can get such an object by calling the
getInstanceclass method. You can use this capability to evaluate the runtime of any chunk of code. All you have to do is create a
Calendarobject before the test code starts, create another
Calendarobject 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 TestRuntime 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
iis 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.