org.deckfour.xes.util
Class XTimer

java.lang.Object
  extended by org.deckfour.xes.util.XTimer

public class XTimer
extends Object

This class implements a simple timer that can be used to quickly profile the speed of operations within library components. The timer simply uses the system time for timing, and thus does not incur significant overhead on runtime.

Author:
Christian W. Guenther (christian@deckfour.org)

Field Summary
static long DAY_MILLIS
          Milliseconds in one day.
static long HOUR_MILLIS
          Milliseconds in one hour.
static long MINUTE_MILLIS
          Milliseconds in one minute.
static long SECOND_MILLIS
          Milliseconds in one second.
protected  long start
          Start time of timer.
protected  long stop
          Stop time of timer.
 
Constructor Summary
XTimer()
          Creates a new timer.
 
Method Summary
static String formatDuration(long millis)
          Formats a duration in milliseconds as a pretty-print string.
 long getDuration()
          Retrieve the runtime of the timer.
 String getDurationString()
          Retrieve the runtime of the timer as a pretty-print string.
 void start()
          Starts the timer.
 void stop()
          Stops the timer (takes time).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DAY_MILLIS

public static final long DAY_MILLIS
Milliseconds in one day.

See Also:
Constant Field Values

HOUR_MILLIS

public static final long HOUR_MILLIS
Milliseconds in one hour.

See Also:
Constant Field Values

MINUTE_MILLIS

public static final long MINUTE_MILLIS
Milliseconds in one minute.

See Also:
Constant Field Values

SECOND_MILLIS

public static final long SECOND_MILLIS
Milliseconds in one second.

See Also:
Constant Field Values

start

protected long start
Start time of timer.


stop

protected long stop
Stop time of timer.

Constructor Detail

XTimer

public XTimer()
Creates a new timer. (starts running implicitly)

Method Detail

start

public void start()
Starts the timer.


stop

public void stop()
Stops the timer (takes time).


getDuration

public long getDuration()
Retrieve the runtime of the timer.

Returns:
Runtime between start (or creation of timer) and stop, in milliseconds.

getDurationString

public String getDurationString()
Retrieve the runtime of the timer as a pretty-print string.

Returns:
Runtime between start (or creation of timer) and stop, as a pretty-print string.

formatDuration

public static String formatDuration(long millis)
Formats a duration in milliseconds as a pretty-print string.

Parameters:
millis - Duration in milliseconds.
Returns:
Given duration as a pretty-print string.