|
SSJ V. 1.2.5. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectumontreal.iro.lecuyer.util.Chrono
public class Chrono
Chrono is a small class that acts as an interface to
the system clock and calculates the CPU time consumed by
parts of a program. Part of this class is implemented in the C language and the
implementation is unfortunately operating system-dependent.
The C functions for the current class have been compiled on a 32-bit machine
running Linux and will not work on 64-bit machines.
For a platform-independent CPU timer (valid only with Java-1.5 or later),
one should use the subclass ChronoSingleThread
which is programmed
directly in Java (see the next class in this guide).
Every object of class Chrono acts as an independent stopwatch.
Several Chrono 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 Chrono.
Below is an example of how it may be used. A stopwatch named timer is constructed (and initialized). When 2.1 seconds of CPU 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.
Constructor Summary | |
---|---|
Chrono()
Constructs a Chrono object and initializes it to zero. |
Method Summary | |
---|---|
static Chrono |
createForSingleThread()
Creates a Chrono instance adapted for a program using a single thread. |
String |
format()
Converts the CPU time used by the program since its last call to init for this Chrono to a String in
the HH:MM:SS.xx format. |
static String |
format(double time)
Converts the time time, given in seconds, to a String in the HH:MM:SS.xx format. |
double |
getHours()
Returns the CPU time in hours used by the program since the last call to init for this Chrono. |
double |
getMinutes()
Returns the CPU time in minutes used by the program since the last call to init for this Chrono. |
double |
getSeconds()
Returns the CPU time in seconds used by the program since the last call to init for this Chrono. |
void |
init()
Initializes this Chrono to zero. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Chrono()
Method Detail |
---|
public static Chrono createForSingleThread()
ChronoSingleThread
which can
measure CPU time for one thread. Under Java versions prior to
1.5, this returns an instance of this class.
This method must not be used to create a timer for a
multi-threaded program, because the obtained CPU times
will differ depending on the used Java version.
public void init()
public double getSeconds()
init
for this Chrono.
public double getMinutes()
init
for this Chrono.
public double getHours()
init
for this Chrono.
public String format()
init
for this Chrono to a String
in
the HH:MM:SS.xx format.
public static String format(double time)
String
in the HH:MM:SS.xx format.
|
SSJ V. 1.2.5. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |