Lattice Tester Online Documentation 0.1.0-861
Software Package For Testing The Uniformity Of Integral Lattices In The Real Space
|
This class acts as an interface to the system clock to compute the CPU time used by parts of a program. More...
#include <latticetester/Chrono.h>
Public Types | |
enum | TimeFormat { SEC , MIN , HOURS , DAYS , HMS } |
Types of units in which the time on a Chrono can be read or printed: in seconds (SEC ), minutes (MIN ), hours (HOUR ), days (DAYS ), or in the HH:MM:SS.xx format, with hours, minutes, seconds and hundreths of a second (HMS ). More... | |
Public Member Functions | |
Chrono () | |
Constructor for a stopwatch; initializes it to zero. | |
~Chrono () | |
Destructor. | |
void | init () |
(Re)Initializes this stopwatch to zero. | |
double | val (TimeFormat unit) |
Returns the CPU time measured by this Chrono since the last call to init() . | |
void | write (TimeFormat unit) |
Prints, on standard output, the CPU time measured by this Chrono since its last call to init() . | |
std::string | toString () |
Returns as a string the CPU time measured by this Chrono since its last call to init() . | |
bool | timeOver (double limit) |
Returns true if this Chrono has reached the time limit (in seconds), otherwise returns false . | |
void | tick () |
Function returning the CPU time used by the program since it was started. | |
Public Attributes | |
uint64_t | microsec |
Microseconds. | |
uint64_t | second |
Seconds. | |
This class acts as an interface to the system clock to compute the CPU time used by parts of a program.
Even though the ANSI/ISO macro CLOCKS_PER_SEC = 1000000
is the number of clock ticks per second for the value returned by the ANSI-C standard clock
function (so this function returns the number of microseconds), on some systems where the 32-bit type long
is used to measure time, the value returned by clock
wraps around to negative values after about 36 minutes. On some other systems where time is measured using the 32-bit type unsigned long
, the clock may wrap around to 0 after about 72 minutes. When the macro USE_ANSI_CLOCK
is undefined, a non-ANSI-C clock is used. On Linux-Unix systems, it calls the POSIX function times
to get the CPU time used by a program. On a Windows platform (when the macro HAVE_WINDOWS_H
is defined), the Windows function GetProcessTimes
will be used to measure the CPU time used by programs. On Linux \(|\)Unix platforms, if the macro USE_ANSI_CLOCK
is defined, the timers will call the ANSI C clock
function. When USE_ANSI_CLOCK
is left undefined, class Chrono
gets the CPU time used by a program via an alternate non-ANSI C timer based on the POSIX (The Portable Operating System Interface) function times
, assuming this function is available. The POSIX standard is described in the IEEE Std 1003.1-2001 document (see The Open Group web site at http://www.opengroup.org/onlinepubs/007904975/toc.htm).
Every object Chrono
acts as an independent stopwatch. Several such stopwatchs can run at any given time. An object of type Chrono
must be declared for each of them. The method init
resets the stopwatch to zero, val
returns its current reading, and write
writes this reading to the current output. The returned value includes part of the execution time of the functions from class Chrono
. The TimeFormat
allows one to choose the kind of time units that are used.
Below is an example of how the functions may be used. A stopwatch named timer
is declared and created. After 2.1 seconds of CPU time have been consumed, the stopwatch is read and reset. Then, after an additional 330 seconds (or 5.5 minutes) of CPU time the stopwatch is read again, printed to the output and deleted.
Chrono timer;
(...) (suppose 2.1 CPU seconds are used here.)
double t = timer.val (Chrono::SEC); // Here, t = 2.1
timer.init();
(...) (suppose 330 CPU seconds are used here.)
t = timer.val (Chrono::MIN); // Here, t = 5.5
timer.write (Chrono::HMS); // Prints: 00:05:30.00
LatticeTester::Chrono::Chrono | ( | ) |
Constructor for a stopwatch; initializes it to zero.
One may reinitialize it later by calling init
.
|
inline |
Destructor.
void LatticeTester::Chrono::init | ( | ) |
(Re)Initializes this stopwatch to zero.
void LatticeTester::Chrono::tick | ( | ) |
Function returning the CPU time used by the program since it was started.
This function depends on the operation system and is not intended to be manipulated directly.
bool LatticeTester::Chrono::timeOver | ( | double | limit | ) |
Returns true
if this Chrono
has reached the time limit
(in seconds), otherwise returns false
.
std::string LatticeTester::Chrono::toString | ( | ) |
double LatticeTester::Chrono::val | ( | TimeFormat | unit | ) |
void LatticeTester::Chrono::write | ( | TimeFormat | unit | ) |
uint64_t LatticeTester::Chrono::microsec |
Microseconds.
uint64_t LatticeTester::Chrono::second |
Seconds.