Package 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.
- Version:
- $Revision: 1.4 $
- Author:
- Dale Anson
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
start
public long start()
Starts/restarts the stopwatch.stop
must be called prior to restart.- Returns:
- the start time, the long returned System.currentTimeMillis().
-
stop
public long stop()
Stops the stopwatch.- Returns:
- the stop time, the long returned System.currentTimeMillis().
-
total
public long total()
Total cumulative elapsed time.- Returns:
- the total time
-
elapsed
public long elapsed()
Elapsed time, difference between the last start time and now.- Returns:
- the elapsed time
-
getName
public java.lang.String getName()
- Returns:
- the name of this StopWatch
-
format
public java.lang.String format(long ms)
Formats the given time into decimal seconds.- Returns:
- the time formatted as mm:ss.ddd
-
toString
public java.lang.String toString()
Returns the total elapsed time of the stopwatch formatted in decimal seconds.- Overrides:
toString
in classjava.lang.Object
- Returns:
- [name: mm:ss.ddd]
-
main
public static void main(java.lang.String[] args)
-
-