edu.cmu.sphinx.util
Class Timer

java.lang.Object
  extended by edu.cmu.sphinx.util.Timer

public class Timer
extends java.lang.Object

Keeps track of execution times. This class provides methods that can be used for timing processes. The process to be timed should be bracketed by calls to timer.start() and timer.stop(). Repeated operations can be timed more than once. The timer will report the minimum, maximum, average and last time executed for all start/stop pairs when the timer.dump is called.

Timer instances can be obtained from a global cache implemented in TimerPool.

See Also:
TimerPool

Method Summary
 void dump()
          Dump the timer.
 double getAverageTime()
          Gets the average time for this timer in milliseconds
 long getCount()
          Gets the count of starts for this timer
 long getCurTime()
          Returns the latest time gathered
 long getMaxTime()
          Gets the max time for this timer in milliseconds
 long getMinTime()
          Gets the min time for this timer in milliseconds
 java.lang.String getName()
          Retrieves the name of the timer
 boolean isStarted()
          Returns true if the timer has started.
 void reset()
          Resets the timer as if it has never run before.
 void start()
          Starts the timer running.
 void start(long time)
          Starts the timer at the given time.
 void stop()
          Stops the timer.
 long stop(boolean verbose)
          Stops the timer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Retrieves the name of the timer

Returns:
the name of the timer

reset

public void reset()
Resets the timer as if it has never run before.


isStarted

public boolean isStarted()
Returns true if the timer has started.

Returns:
true if the timer has started; false otherwise

start

public void start()
Starts the timer running.


start

public void start(long time)
Starts the timer at the given time.

Parameters:
time - the starting time

stop

public long stop(boolean verbose)
Stops the timer.

Parameters:
verbose - if true, print out details from this run; otherwise, don't print the details
Returns:
the duration since start in milliseconds

stop

public void stop()
Stops the timer.


dump

public void dump()
Dump the timer. Shows the timer details.


getCount

public long getCount()
Gets the count of starts for this timer

Returns:
the count

getCurTime

public long getCurTime()
Returns the latest time gathered

Returns:
the time in milliseconds

getAverageTime

public double getAverageTime()
Gets the average time for this timer in milliseconds

Returns:
the average time

getMinTime

public long getMinTime()
Gets the min time for this timer in milliseconds

Returns:
the min time

getMaxTime

public long getMaxTime()
Gets the max time for this timer in milliseconds

Returns:
the max time in milliseconds