public class Stopwatch extends Object
Stopwatchdata type is for measuring the time that elapses between the start and end of a programming task (wall-clock time). See
StopwatchCPUfor a version that measures CPU time. For additional documentation, see Section 1.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
|Constructor and Description|
Initializes a new stopwatch.
|Modifier and Type||Method and Description|
Returns the elapsed CPU time (in seconds) since the stopwatch was created.
Unit tests the
public double elapsedTime()
public static void main(String args)
Stopwatchdata type. Takes a command-line argument
nand computes the sum of the square roots of the first
npositive integers, first using
Math.sqrt(), then using
Math.pow(). It prints to standard output the sum and the amount of time to compute the sum. Note that the discrete sum can be approximated by an integral - the sum should be approximately 2/3 * (n^(3/2) - 1).
args- the command-line arguments