public class ElapsedTime
extends java.lang.Object
ElapsedTime
class provides a simple handy timer to measure elapsed time intervals.
The timer does not provide events or callbacks, as some other timers do. Rather, at an application-
determined juncture, one can reset()
the timer. Thereafter, one can query the interval
of wall-clock time that has subsequently elapsed by calling the time()
, seconds()
,
or milliseconds()
methods. The timer has nanosecond internal accuracy. The precision
reported by the time()
method is either seconds or milliseconds, depending on how the
timer is initially constructed. This class is not thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
ElapsedTime.Resolution
An indicator of the resolution of a timer.
|
Modifier and Type | Field and Description |
---|---|
static double |
dMILLIS_IN_NANO
Deprecated.
use MILLIS_IN_NANO instead
|
static double |
dSECOND_IN_NANO
Deprecated.
use SECOND_IN_NANO instead
|
static long |
lMILLIS_IN_NANO
Deprecated.
use MILLIS_IN_NANO instead
|
static long |
lSECOND_IN_NANO
Deprecated.
use SECOND_IN_NANO instead
|
static long |
MILLIS_IN_NANO
the number of nanoseconds in a millisecond
|
static long |
SECOND_IN_NANO
the number of nanoseconds in a second
|
Constructor and Description |
---|
ElapsedTime()
Creates a timer with resolution
Resolution.Seconds
that is initialized with the now-current time. |
ElapsedTime(ElapsedTime.Resolution resolution)
Creates a timer with a resolution of seconds or milliseconds.
|
ElapsedTime(long startTime)
Creates a timer with resolution
Resolution.Seconds . |
Modifier and Type | Method and Description |
---|---|
ElapsedTime.Resolution |
getResolution()
Returns the resolution with which the timer was instantiated.
|
void |
log(java.lang.String label)
Log a message stating how long the timer has been running
|
double |
milliseconds()
Returns the same data as does
time() , but always in millisecond units |
void |
reset()
Resets the internal state of the timer to reflect the current time.
|
double |
seconds()
Returns the same data as does
time() , but always in units of seconds |
double |
startTime()
Returns, in resolution-dependent units, the time at which this timer was last reset.
|
double |
time()
Returns the duration that has elapsed since the last reset of this timer.
|
java.lang.String |
toString()
Returns a string indicating the current elapsed time of the timer.
|
@Deprecated public static final double dSECOND_IN_NANO
@Deprecated public static final long lSECOND_IN_NANO
@Deprecated public static final double dMILLIS_IN_NANO
@Deprecated public static final long lMILLIS_IN_NANO
public static final long SECOND_IN_NANO
public static final long MILLIS_IN_NANO
public ElapsedTime()
Resolution.Seconds
that is initialized with the now-current time.ElapsedTime(long)
,
ElapsedTime(Resolution)
public ElapsedTime(long startTime)
Resolution.Seconds
.
The timer is initialized with the provided start time. Zero is often a useful value to provide
here: in common usage such timers will often be processed by application logic virtually immediately.startTime
- the initial value of the timerElapsedTime()
public ElapsedTime(ElapsedTime.Resolution resolution)
time()
method reports. The timer is initialized
with the current time.resolution
- the resolution of the new timerElapsedTime()
public void reset()
time()
will report as zero.time()
public double startTime()
public double time()
ElapsedTime()
,
ElapsedTime(Resolution)
,
seconds()
,
milliseconds()
public double seconds()
time()
, but always in units of secondstime()
public double milliseconds()
time()
, but always in millisecond unitstime()
public ElapsedTime.Resolution getResolution()
public void log(java.lang.String label)
public java.lang.String toString()
toString
in class java.lang.Object