net.sf.antcontrib.perf
Class StopWatch
java.lang.Object
net.sf.antcontrib.perf.StopWatch
public class StopWatch
extends java.lang.Object
A stopwatch, useful for 'quick and dirty' performance testing. Typical usage:
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.
long | elapsed() - Elapsed time, difference between the last start time and now.
|
String | format(long ms) - Formats the given time into decimal seconds.
|
String | getName()
|
static void | main(String[] args)
|
long | start() - Starts/restarts the stopwatch.
|
long | stop() - Stops the stopwatch.
|
String | toString() - Returns the total elapsed time of the stopwatch formatted in decimal seconds.
|
long | total() - Total cumulative elapsed time.
|
StopWatch
public StopWatch()
Starts the stopwatch.
StopWatch
public StopWatch(String name)
Starts the stopwatch.
name
- an identifying name for this StopWatch
elapsed
public long elapsed()
Elapsed time, difference between the last start time and now.
format
public String format(long ms)
Formats the given time into decimal seconds.
- the time formatted as mm:ss.ddd
getName
public String getName()
- the name of this StopWatch
main
public static void main(String[] args)
start
public long start()
Starts/restarts the stopwatch. stop
must be called prior
to restart.
- the start time, the long returned System.currentTimeMillis().
stop
public long stop()
Stops the stopwatch.
- the stop time, the long returned System.currentTimeMillis().
toString
public String toString()
Returns the total elapsed time of the stopwatch formatted in decimal seconds.
total
public long total()
Total cumulative elapsed time.