common
Class Timer

java.lang.Object
  extended by common.Timer

public class Timer
extends java.lang.Object

A class for measuring how much time a program spends doing certain operations. Each Timer object acts like a stopwatch that keeps track of an elapsed time. When you call the start method, the elapsed time starts increasing; when you call the stop method, it stops. Unlike a stopwatch, there is no "reset" method. There is also a static method printAllTimers which you can call at the end of a program to get the elapsed time for every timer created during this run of the program.


Constructor Summary
Timer()
          Creates a new Timer that will not be registered to have its its time printed by Timer.printAllTimers.
Timer(java.lang.String name)
          Creates a new Timer with the given name, and registers it so that its elapsed time will be printed by Timer.printAllTimers.
 
Method Summary
 double elapsedTime()
          Returns the total elapsed time in seconds.
static void printAllTimers()
          Prints the elapsed times for all timers created by the program.
 void start()
          Starts the timer.
 void stop()
          Stops the timer, and adds the time elapsed since the last call to start() to the running total.
 java.lang.String toString()
          Returns a string containing this Timer's name and elapsed time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
Creates a new Timer that will not be registered to have its its time printed by Timer.printAllTimers.


Timer

public Timer(java.lang.String name)
Creates a new Timer with the given name, and registers it so that its elapsed time will be printed by Timer.printAllTimers.

Method Detail

start

public final void start()
Starts the timer.


stop

public final void stop()
Stops the timer, and adds the time elapsed since the last call to start() to the running total.


elapsedTime

public double elapsedTime()
Returns the total elapsed time in seconds.


toString

public java.lang.String toString()
Returns a string containing this Timer's name and elapsed time.

Overrides:
toString in class java.lang.Object

printAllTimers

public static void printAllTimers()
Prints the elapsed times for all timers created by the program.