Class StopWatch

java.lang.Object
ise.antelope.tasks.StopWatch

public class StopWatch extends 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
 
 
Version:
$Revision: 131 $
  • Constructor Summary

    Constructors
    Constructor
    Description
    Starts the stopwatch.
    Starts the stopwatch.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Elapsed time, difference between the last start time and now.
    format(long ms)
    Formats the given time into decimal seconds.
     
    static void
    main(String[] args)
     
    long
    Starts/restarts the stopwatch.
    long
    Stops the stopwatch.
    Returns the total elapsed time of the stopwatch formatted in decimal seconds.
    long
    Total cumulative elapsed time, stops the stopwatch.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • StopWatch

      public StopWatch()
      Starts the stopwatch.
    • StopWatch

      public StopWatch(String name)
      Starts the stopwatch.
      Parameters:
      name - an identifying name for this StopWatch
  • Method Details

    • 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, stops the stopwatch.
      Returns:
      the total time
    • elapsed

      public long elapsed()
      Elapsed time, difference between the last start time and now.
      Returns:
      the elapsed time
    • getName

      public String getName()
      Returns:
      the name of this StopWatch
    • format

      public String format(long ms)
      Formats the given time into decimal seconds.
      Returns:
      the time formatted as mm:ss.ddd
    • toString

      public String toString()
      Returns the total elapsed time of the stopwatch formatted in decimal seconds.
      Overrides:
      toString in class Object
      Returns:
      [name: mm:ss.ddd]
    • main

      public static void main(String[] args)