public class StopWatch
extends java.lang.Object
StopWatch sw = new StopWatch(); // automatically starts // do something here... sw.stop(); System.out.println(sw.toString()); // print the total sw.start(); // restart the stopwatch // do some more things... sw.stop(); System.out.println(sw.format(sw.elapsed()); // print the time since the last start System.out.println(sw.toString()); // print the cumulative total
Developed for use with Antelope, migrated to ant-contrib Oct 2003.
Constructor and Description |
---|
StopWatch()
Starts the stopwatch.
|
StopWatch(java.lang.String name)
Starts the stopwatch.
|
Modifier and Type | Method and Description |
---|---|
long |
elapsed()
Elapsed time, difference between the last start time and now.
|
java.lang.String |
format(long ms)
Formats the given time into decimal seconds.
|
java.lang.String |
getName() |
static void |
main(java.lang.String[] args) |
long |
start()
Starts/restarts the stopwatch.
|
long |
stop()
Stops the stopwatch.
|
java.lang.String |
toString()
Returns the total elapsed time of the stopwatch formatted in decimal seconds.
|
long |
total()
Total cumulative elapsed time.
|
public StopWatch()
public StopWatch(java.lang.String name)
name
- an identifying name for this StopWatchpublic long start()
stop
must be called prior
to restart.public long stop()
public long total()
public long elapsed()
public java.lang.String getName()
public java.lang.String format(long ms)
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)