SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.util.AbstractChrono Class Referenceabstract

AbstractChrono is the base class for timer (stopwatch) objects that can measure the CPU time or wall clock time elapsed when executing parts of a program. More...

Inheritance diagram for umontreal.ssj.util.AbstractChrono:
umontreal.ssj.util.Chrono umontreal.ssj.util.ChronoSingleThread umontreal.ssj.util.ChronoWall

Timing functions @{

void init ()
 Initializes this AbstractChrono to zero.
double getSeconds ()
 Returns the CPU time in seconds used by the program since the last call to init for this AbstractChrono.
double getMinutes ()
 Returns the CPU time in minutes used by the program since the last call to init for this AbstractChrono.
double getHours ()
 Returns the CPU time in hours used by the program since the last call to init for this AbstractChrono.
String format ()
 Converts the CPU time used by the program since its last call to init for this AbstractChrono 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.

Detailed Description

AbstractChrono is the base class for timer (stopwatch) objects that can measure the CPU time or wall clock time elapsed when executing parts of a program.

Its main implementations are the Chrono and ChronoWall classes.

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.

AbstractChrono timer = new Chrono();
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
Definition Chrono.java:37

(suppose 2.1 CPU seconds are used here.)

double t = timer.getSeconds(); // Here, t = 2.1 timer.init(); t =
timer.getSeconds(); // Here, t = 0.0
double getSeconds()
Returns the CPU time in seconds used by the program since the last call to init for this AbstractChro...

(suppose 330 CPU seconds are used here.)

t = timer.getMinutes(); // Here, t = 5.5 System.out.println
(timer.format()); // Prints: 0:5:30.00
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
double getMinutes()
Returns the CPU time in minutes used by the program since the last call to init for this AbstractChro...

Definition at line 71 of file AbstractChrono.java.

Member Function Documentation

◆ format() [1/2]

String umontreal.ssj.util.AbstractChrono.format ( )

Converts the CPU time used by the program since its last call to init for this AbstractChrono to a String in the HH:MM:SS.xx format.

Returns
the string representation of the CPU time

Definition at line 137 of file AbstractChrono.java.

◆ format() [2/2]

String umontreal.ssj.util.AbstractChrono.format ( double time)
static

Converts the time time, given in seconds, to a String in the HH:MM:SS.xx format.

Returns
the string representation of the time time

Definition at line 147 of file AbstractChrono.java.

◆ getHours()

double umontreal.ssj.util.AbstractChrono.getHours ( )

Returns the CPU time in hours used by the program since the last call to init for this AbstractChrono.

Returns
the number of hours

Definition at line 125 of file AbstractChrono.java.

◆ getMinutes()

double umontreal.ssj.util.AbstractChrono.getMinutes ( )

Returns the CPU time in minutes used by the program since the last call to init for this AbstractChrono.

Returns
the number of minutes

Definition at line 113 of file AbstractChrono.java.

◆ getSeconds()

double umontreal.ssj.util.AbstractChrono.getSeconds ( )

Returns the CPU time in seconds used by the program since the last call to init for this AbstractChrono.

Returns
the number of seconds

Definition at line 101 of file AbstractChrono.java.

◆ init()

void umontreal.ssj.util.AbstractChrono.init ( )

Initializes this AbstractChrono to zero.

Definition at line 89 of file AbstractChrono.java.


The documentation for this class was generated from the following file: