public class StopWatch
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.io.PrintWriter |
defaultOutput |
private java.io.PrintWriter |
out |
private long |
time |
static java.util.Map<java.lang.String,StopWatch> |
watches |
Constructor and Description |
---|
StopWatch() |
StopWatch(boolean start) |
StopWatch(boolean start,
java.io.PrintStream output) |
StopWatch(boolean start,
java.io.PrintWriter output) |
Modifier and Type | Method and Description |
---|---|
void |
clearNamed()
Remove all named StopWatches
|
static StopWatch |
create(java.lang.String name,
boolean started)
Create a new named StopWatch and optionally start it if `started` is true.
|
long |
elapsed()
The total elapsed time in milliseconds.
|
static long |
elapsed(java.lang.String watchName)
Get the elapsed time of the named StopWatch.
|
static StopWatch |
enter(java.lang.String watchName)
Gets the named StopWatch and starts it.
|
static StopWatch |
exit(java.lang.String watchName)
Gets the named StopWatch and stops it.
|
static StopWatch |
get(java.lang.String name)
Get named StopWatch if it exists.
|
static StopWatch |
get(java.lang.String name,
boolean createStarted)
Get named StopWatch if it exists.
|
boolean |
isStarted() |
void |
printAll()
Prints the elapsed time and current state of all named StopWatches.
|
void |
printAll(long totalElapsed)
Prints the elapsed time and current state of all named StopWatches
|
void |
printAll(java.lang.String format,
long totalElapsed)
Prints the elapsed time and current state of all named StopWatches using the specified format.
|
StopWatch |
printf(java.lang.String message,
java.lang.Object... args) |
static StopWatch |
printf(java.lang.String watchName,
java.lang.String message,
java.lang.Object... args)
Write a message to the named StopWatch.
|
StopWatch |
println(java.lang.String message) |
static StopWatch |
println(java.lang.String watchName,
java.lang.String message)
Write a message to the named StopWatch.
|
StopWatch |
reset()
Reset elapsed time to 0 and stop the timer.
|
StopWatch |
restart()
Reset elapsed time to 0 and start the timer.
|
StopWatch |
start()
Start the timer.
|
StopWatch |
stop()
Stop the timer, but store the elapsed time so that when
start() is called,
the elapsed time will continue to increase. |
static long |
time() |
public static java.io.PrintWriter defaultOutput
private java.io.PrintWriter out
private long time
public static final java.util.Map<java.lang.String,StopWatch> watches
public StopWatch()
public StopWatch(boolean start)
public StopWatch(boolean start, java.io.PrintStream output)
public StopWatch(boolean start, java.io.PrintWriter output)
public void clearNamed()
public static StopWatch create(java.lang.String name, boolean started)
public long elapsed()
public static long elapsed(java.lang.String watchName)
public static StopWatch enter(java.lang.String watchName)
public static StopWatch exit(java.lang.String watchName)
public static StopWatch get(java.lang.String name)
public static StopWatch get(java.lang.String name, boolean createStarted)
public boolean isStarted()
public void printAll()
public void printAll(long totalElapsed)
public void printAll(java.lang.String format, long totalElapsed)
"\t%1$5d\t%2$3s\t%2$s%n"
public StopWatch printf(java.lang.String message, java.lang.Object... args)
public static StopWatch printf(java.lang.String watchName, java.lang.String message, java.lang.Object... args)
public StopWatch println(java.lang.String message)
public static StopWatch println(java.lang.String watchName, java.lang.String message)
public StopWatch reset()
public StopWatch restart()
public StopWatch start()
public StopWatch stop()
start()
is called,
the elapsed time will continue to increase.
If the timer is already stopped, this has no effect.public static long time()