public class StopWatch
extends java.lang.Object
The timer starts when you create the object. Subsequent calls will return information
based on the elapsed wall-clock time since the object was created. If stop
is called, it will fix the end time.
Constructor and Description |
---|
StopWatch()
Create a stopwatch.
|
Modifier and Type | Method and Description |
---|---|
long |
duration()
The number of milliseconds that the stopwatch has been running.
|
java.lang.String |
elapsed()
The elapsed time in a human-friendly format.
|
java.lang.String |
elapsed(long duration)
The elapsed time in a human-friendly format.
|
java.lang.String |
perSecond(long events)
Compute events per second.
|
void |
stop()
Stop the watch.
|
public StopWatch()
Time begins counting immediately.
public void stop()
After calling this method, the time will remain fixed.
public long duration()
Or, if stop
has been called, how long it ran.
public java.lang.String perSecond(long events)
Computes events per second for the given number of events. It returns
a string of the form %3.1f
.
events
- The number of eventspublic java.lang.String elapsed()
This method uses the timer's elapsed time.
public java.lang.String elapsed(long duration)
Returns the number of days, minutes, hours, and seconds represented by the duration, a number of milliseconds. For example, 103,010,000ms is "1d4h36m50s".
duration
- the duration in milliseconds