edu.cmu.sphinx.util
Class Timer

java.lang.Object
  extended byedu.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.


Method Summary
 void dump()
          Dump the timer.
static void dumpAll()
          Dump all timers
 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
static Timer getTimer(java.lang.String timerName)
          Retrieves (or creates) a timer with the given name
 boolean isStarted()
          Returns true if the timer has started.
 void reset()
          Resets the timer as if it has never run before.
static void resetAll()
          Resets all timers
 void start()
          Starts the timer running.
 void start(long time)
          Starts the timer at the given time.
static void start(java.lang.String name)
          Starts a timer by name
 void stop()
          Stops the timer.
 long stop(boolean verbose)
          Stops the timer.
static void stop(java.lang.String name)
          Stops a timer by name
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTimer

public static Timer getTimer(java.lang.String timerName)
Retrieves (or creates) a timer with the given name

Parameters:
timerName - the name of the particular timer to retrieve. If the timer does not already exist, it will be created
Returns:
the timer.

dumpAll

public static void dumpAll()
Dump all timers


resetAll

public static void resetAll()
Resets all timers


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.


start

public static void start(java.lang.String name)
Starts a timer by name

Parameters:
name - the name of the timer to start

stop

public static void stop(java.lang.String name)
Stops a timer by name

Parameters:
name - the name of the timer to stop

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