SSJ  3.3.1
Stochastic Simulation in Java
Protected Member Functions | List of all members
AbstractChrono Class Referenceabstract

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. More...

Inheritance diagram for AbstractChrono:
[legend]

Protected Member Functions

abstract void getTime (long[] tab)
 

Timing functions

 AbstractChrono ()
 
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. More...
 
double getMinutes ()
 Returns the CPU time in minutes used by the program since the last call to init for this AbstractChrono. More...
 
double getHours ()
 Returns the CPU time in hours used by the program since the last call to init for this AbstractChrono. More...
 
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. More...
 
static String format (double time)
 Converts the time time, given in seconds, to a String in the HH:MM:SS.xx format. More...
 

Detailed Description

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.

AbstractChrono timer = new Chrono();
\vdots

(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
\vdots

(suppose 330 CPU seconds are used here.)

t = timer.getMinutes(); // Here, t = 5.5
System.out.println (timer.format()); // Prints: 0:5:30.00

Warning:

Even though the ANSI/ISO macro CLOCKS_PER_SEC = 1000000 is the number of clock ticks per second for the value returned by the clock function (so this function returns the number of microseconds), on some systems the value returned by clock wraps around to 0 after about 36 minutes when the type long used to measure time has only 32 bits (on some systems, the clock may wrap around to 0 after about 72 minutes if time is measured using the 32-bit type unsigned long). When the macro USE_ANSI_CLOCK in module gdef is undefined, a non-ANSI clock is used. It calls the POSIX function times to get the CPU time used by a program and the non-ANSI macro CLK_TCK is used to get the real number of clock ticks per second for the system.

Member Function Documentation

◆ format() [1/2]

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.

Returns
the string representation of the CPU time

◆ format() [2/2]

static String 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

◆ getHours()

double 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

◆ getMinutes()

double 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

◆ getSeconds()

double 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

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