ibis.util
Class Timer

java.lang.Object
  extended byibis.util.Timer
All Implemented Interfaces:
java.io.Serializable

public class Timer
extends java.lang.Object
implements java.io.Serializable

Utility for measuring time.

See Also:
Serialized Form

Method Summary
 double accuracy()
          Returns accuracy of this timer in seconds.
 void add(Timer t)
           
 java.lang.String averageTime()
          Returns the average measured time in microseconds, nicely formatted.
 double averageTimeVal()
          Returns the average measured time in microseconds.
static Timer createTimer()
          Returns a Timer instance suitable for the system at hand.
static Timer createTimer(java.lang.String impl)
          Returns a Timer instance indicated by the implementation name provided.
 long currentTimeNanos()
          Returns the current time stamp in nano seconds.
static java.lang.String format(double micros)
          Formats a time in microseconds
 java.lang.String implementationName()
          Returns implementation name of this timer ("e.g., "javaTimer").
 java.lang.String lastTime()
          Returns the last measured time in microseconds, nicely formatted.
 double lastTimeVal()
          Returns the last measured time in microseconds.
 int nrTimes()
          Returns the number of measurements.
 void reset()
          Resets the timer.
 void start()
          Starts the timer.
 void stop()
          Stops the timer.
 java.lang.String totalTime()
          Returns the total measured time in microseconds, nicely formatted.
 double totalTimeVal()
          Returns the total measured time in microseconds.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

implementationName

public java.lang.String implementationName()
Returns implementation name of this timer ("e.g., "javaTimer").

Returns:
the implementation name.

add

public void add(Timer t)

accuracy

public double accuracy()
Returns accuracy of this timer in seconds. Note that this only gives an upperbound for the precision of this timer.

Returns:
the accuracy.

currentTimeNanos

public long currentTimeNanos()
Returns the current time stamp in nano seconds.

Returns:
the current time stamp.

reset

public void reset()
Resets the timer.


totalTimeVal

public double totalTimeVal()
Returns the total measured time in microseconds.

Returns:
total measured time.

totalTime

public java.lang.String totalTime()
Returns the total measured time in microseconds, nicely formatted.

Returns:
total measured time.

averageTimeVal

public double averageTimeVal()
Returns the average measured time in microseconds.

Returns:
the average measured time.

averageTime

public java.lang.String averageTime()
Returns the average measured time in microseconds, nicely formatted.

Returns:
the average measured time.

lastTimeVal

public double lastTimeVal()
Returns the last measured time in microseconds.

Returns:
the last measured time.

lastTime

public java.lang.String lastTime()
Returns the last measured time in microseconds, nicely formatted.

Returns:
the last measured time.

nrTimes

public int nrTimes()
Returns the number of measurements.

Returns:
the number of measurements.

start

public void start()
Starts the timer. If the timer is already started, this is a no-op. The next stop()call will stop the timer and add the result to the total.


stop

public void stop()
Stops the timer. If the timer is not started, this is a no-op. The timer is stopped, and the time between the last start()and "now" is added to the total.


format

public static java.lang.String format(double micros)
Formats a time in microseconds

Parameters:
micros - the time to be formatted.
Returns:
the result of the format.

createTimer

public static Timer createTimer(java.lang.String impl)
Returns a Timer instance indicated by the implementation name provided. Returns the default timer when the implementation could not be loaded. This default could use a native timer, System.currentTimeMillis(), or System.nanoTime() if it exists. The accuracy of the timer can be obtained through the accuracy() method.

Parameters:
impl - the name of the Timer implementation.
Returns:
the new Timer instance.

createTimer

public static Timer createTimer()
Returns a Timer instance suitable for the system at hand.

Returns:
the new Timer instance.


The Ibis project