maspack.util
Class FunctionTimer

java.lang.Object
  extended by maspack.util.FunctionTimer

public class FunctionTimer
extends java.lang.Object

Class to measure the elapsed time between events, as marked by calls to the start and stop methods. Mainly intended for use in timing the execution speed of functions.


Constructor Summary
FunctionTimer()
          Create a new FunctionTimer
 
Method Summary
 double getResolutionUsec()
          Returns the resolution of this timer, in microseconds.
 double getTimeUsec()
          Returns the elapsed time in microseconds.
 void reset()
          Sets the elapsed time to 0 and re-initializes the start indicator
 void restart()
          Marks the beginning of a new timing interval and leaves the elapsed time unchanged.
 java.lang.String result(int cnt)
          Returns a string describing the current elapsed time, divided by the supplied count parameter.
 java.lang.String resultMsec(int cnt)
          Returns a string describing the current elapsed time, divided by the supplied count parameter.
 java.lang.String resultUsec(int cnt)
          Returns a string describing the current elapsed time, divided by the supplied count parameter.
 void start()
          Marks the beginning of a new timing interval and sets the elapsed time to 0.
 void stop()
          Adds the time difference between the current time and the last time start or restart was called to the elapsed time.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionTimer

public FunctionTimer()
Create a new FunctionTimer

Method Detail

start

public void start()
Marks the beginning of a new timing interval and sets the elapsed time to 0.


restart

public void restart()
Marks the beginning of a new timing interval and leaves the elapsed time unchanged.


reset

public void reset()
Sets the elapsed time to 0 and re-initializes the start indicator


stop

public void stop()
Adds the time difference between the current time and the last time start or restart was called to the elapsed time. If start was not previously called, no change is made to the elapsed time.


getTimeUsec

public double getTimeUsec()
Returns the elapsed time in microseconds. If the timer is running (i.e., start or restart has been called but stop has not yet been called, the associated time differece will not be included in the result.

Returns:
elapsed time

getResolutionUsec

public double getResolutionUsec()
Returns the resolution of this timer, in microseconds. This depends on the system calls available for measuring time.

Returns:
timer resolution

result

public java.lang.String result(int cnt)
Returns a string describing the current elapsed time, divided by the supplied count parameter. The resulting divided time is displayed in milliseconds, unless it is less than 1 millisecond, in which case it is displayed in microseconds.

Parameters:
cnt - count to divide the elapsed time by
Returns:
string describing the divdied time

resultUsec

public java.lang.String resultUsec(int cnt)
Returns a string describing the current elapsed time, divided by the supplied count parameter. The resulting divided time is displayed in microseconds.

Parameters:
cnt - count to divide the elapsed time by
Returns:
string describing the divdied time

resultMsec

public java.lang.String resultMsec(int cnt)
Returns a string describing the current elapsed time, divided by the supplied count parameter. The resulting divided time is displayed in milliseconds.

Parameters:
cnt - count to divide the elapsed time by
Returns:
string describing the divdied time