public class Watch extends Object
Measures the duration between start and elapsed or duration in
nanosecond resolution. The returned value is however not necessarily that exact: System.nanoTime()
.
This is intended to replace code like:
long start = System.currentTimeMillis();
//do something
System.out.println("Duration: "+(System.currentTimeMillis() - start));
System.nanoTime()
Modifier and Type | Method and Description |
---|---|
String |
duration()
Boilerplate method for calling duration(false)
|
String |
duration(boolean reset)
Returns the formatted duration.
|
long |
elapsed(TimeUnit unit,
boolean reset)
Returns the number of units since the last call to reset or start.
|
long |
elapsedMillis()
Returns the number of millis since the last call to reset or start.
|
void |
reset()
Resets the watch, so that every duration returned by this instance will be measured from this call on.
|
static Watch |
start()
Creates and starts a new watch.
|
void |
submitMicroTiming(String category,
String key)
Submits the value for this watch to the
Microtiming framework using the given key |
String |
toString() |
public static Watch start()
public void reset()
public long elapsedMillis()
public long elapsed(TimeUnit unit, boolean reset)
unit
- determines the desired output unitreset
- determines if the watch should be reset, after the duration has be computed.public String duration(boolean reset)
This method tries to generate a string which is as short as possible. Therefore, if the duration is
less than one microsecond, the number of nanoseconds is returned. If the duration is less than one millisecond,
the number of microseconds (rounded) is returned. Otherwise, the value is rounded to milliseconds and returned
as
formatted by NLS.convertDuration(long)
.
reset
- determines if the watch should be reset, after the duration has be computed.public String duration()
duration(boolean)
public void submitMicroTiming(@Nonnull String category, @Nonnull String key)
Microtiming
framework using the given keycategory
- selects the category for the given keykey
- the key used to store the elapsed time forCopyright © 2018. All rights reserved.