public class Stopwatch
extends java.lang.Object
Constructor and Description |
---|
Stopwatch()
Default constructor
Creates a new Stopwatch object
|
Modifier and Type | Method and Description |
---|---|
void |
delay()
Inserts a short delay.
|
void |
delay(int delayFactor)
Inserts a delay of the given size.
|
double |
getHours()
Returns the elapsed time in hours, as recorded at the
last call to stop().
|
double |
getMilliSeconds()
Returns the elapsed time in milliseconds, as recorded at the
last call to stop().
|
double |
getMinutes()
Returns the elapsed time in minutes, as recorded at the
last call to stop().
|
double |
getSeconds()
Returns the elapsed time in seconds, as recorded at the
last call to stop().
|
long |
getTicks()
Returns the elapsed time in clock ticks, as recorded at the
last call to stop().
|
static void |
main(java.lang.String[] args) |
void |
start()
Resets this Stopwatch object to the current time.
|
void |
stop()
Records the time elapsed since creation/the last start.
|
public Stopwatch()
Post:
The clock time at the time of declaration has been recorded.
public void start()
Pre:
"self" has been declared.
Post:
The stopwatch timer has been "started" and the clock time at start time has been recorded.
public void stop()
Pre:
start() has been called.
Post:
The stopwatch timer has been "stopped" and the accumulated time since start() was called has been recorded, in clock ticks.
public void delay()
public void delay(int delayFactor)
delayFactor
- The multiplier for the amount of artificial
time delay to insert
Pre:
start() has been called.
Post:
An artificial amount of time has been added to the total computer process time as reported by the clock function. In other words, during this delay time the "stopwatch" continues to accumulate time but nothing else happens. Thus this is a way to make an operation appear to take longer than it actually does. It can be used to cause the stopwatch to accumulate time artificially when monitoring the performance of an algorithm on a relatively small data set. This helps us to overcome the problem of trying to measure the amount of time taken to perform a calculation and finding that it took "no time at all". Note that we still cannot measure the absoute time taken, but fortunately we are only interested in measuring the relative time taken by the same algorithm on data sets of different sizes, or by different algorithms on data sets of the same size. The input parameter delayFactor is a linear multiplier for increasing the amount of delay time. For example, a delayFactor of 2 doubles the amount of delay time accumulated by a single call to the delay() member function.
public long getTicks()
Pre:
start() and stop() have been called (in that order).
Post:
Returns the accumulated time between the times when the stopwatch was last started and stopped, in clock ticks.
public double getMilliSeconds()
Pre:
start() and stop() have been called (in that order).
Post:
Returns the accumulated time between the times when the stopwatch was last started and stopped, in seconds.
public double getSeconds()
Pre:
start() and stop() have been called (in that order).
Post:
Returns the accumulated time between the times when the stopwatch was last started and stopped, in seconds.
public double getMinutes()
Pre:
start() and stop() have been called (in that order).
Post:
Returns the accumulated time between the times wehn the stopwatch was last started and stopped, in minutes.
public double getHours()
Pre:
start() and stop() have been called (in that order).
Post:
Returns the accumulated time between the times when the stopwatch was last started and stopped, in hours.
public static void main(java.lang.String[] args)