SSJ
V. labo.

umontreal.iro.lecuyer.util
Class AbstractChrono

java.lang.Object
  extended by umontreal.iro.lecuyer.util.AbstractChrono
Direct Known Subclasses:
Chrono, ChronoSingleThread, GlobalCPUTimeChrono, SystemTimeChrono, ThreadCPUTimeChrono

public abstract class AbstractChrono
extends Object

AbstractChrono

AbstractChrono is a class that acts as an interface to the system clock and calculates the CPU or system time consumed by parts of a program.

Every object of class AbstractChrono acts as an independent stopwatch. Several AbstractChrono objects can run at any given time. The method init resets the stopwatch to zero, getSeconds, getMinutes and getHours return its current reading, and format converts this reading to a String. The returned value includes the execution time of the method from AbstractChrono.

Below is an example of how it may be used. A stopwatch named timer is constructed (and initialized). When 2.1 seconds of CPU time have been consumed, the stopwatch is read and reset to zero. Then, after an additional 330 seconds (or 5.5 minutes) of CPU time, the stopwatch is read again and the value is printed to the output in minutes.
\begin{vcode}
 \par
 AbstractChrono timer = new Chrono();
 \end{vcode}

\begin{vcode}
 \par
 suppose 2.1 CPU seconds are used here
 \par
 \end{vcode}

\begin{vcode}
 double t = timer.getSeconds(); // Here, t = 2.1
 timer.init();
 t = timer.getSeconds(); // Here, t = 0.0
 \end{vcode}

\begin{vcode}
 \par
 suppose 330 CPU seconds are used here.
 \par
 \end{vcode}

\begin{vcode}
 t = timer.getMinutes(); // Here, t = 5.5
 System.out.println (timer.format()); // Prints: 0:5:30.00
 \end{vcode}


Constructor Summary
AbstractChrono()
           
 
Method Summary
 String format()
          .
static String format(double time)
          .
 double getHours()
          .
 double getMinutes()
          .
 double getSeconds()
          .
 void init()
          .
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractChrono

public AbstractChrono()
Method Detail

init

public void init()
. \begin{tabb}Initializes this \texttt{AbstractChrono} to zero.
 \end{tabb}


getSeconds

public double getSeconds()
. \begin{tabb}
 Returns the CPU time in seconds used by the program since the last call to
 \method{init}{} for this \texttt{AbstractChrono}.
 \end{tabb}
the number of seconds


getMinutes

public double getMinutes()
. \begin{tabb}
 Returns the CPU time in minutes used by the program since the last call to
 \method{init}{} for this \texttt{AbstractChrono}.
 \end{tabb}
the number of minutes


getHours

public double getHours()
. \begin{tabb}
 Returns the CPU time in hours used by the program since the last call to
 \method{init}{} for this \texttt{AbstractChrono}.
 \end{tabb}
the number of hours


format

public String format()
. \begin{tabb}Converts the CPU time used by the program since its last
 call to \m...
 ...ct\-Chrono} to a
 \class{String} in the \texttt{HH:MM:SS.xx} format.
 \end{tabb}
the string representation of the CPU time


format

public static String format(double time)
. \begin{tabb}Converts the time \texttt{time}, given in seconds, to a
 \class{String} in the \texttt{HH:MM:SS.xx} format.
 \end{tabb}
the string representation of the time time


SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.