Aleph-w  1.9
General library for algorithms and data structures
Aleph::Now Class Reference

#include <ahNow.H>

Public Types

enum  Precision {
  Hours, Minutes, Seconds, Milliseconds,
  Microseconds, Nanoseconds
}
 Precision for timing.
 
using ClockType = high_resolution_clock
 
using TimePointType = ClockType::time_point
 
using DurationType = ClockType::duration
 

Public Member Functions

 Now (bool start_now=false)
 Builds a new object with default values. More...
 
 Now (const Precision &_precision, bool start_now=false)
 Builds a new object with parametric precision time. More...
 
const Precisionget_precision () const
 
void set_precision (const Precision &_precision)
 
TimePointType start ()
 
double elapsed ()
 
double delta ()
 

Static Public Member Functions

static int to_int (Precision p)
 
static TimePointType current_time_point ()
 Gets the current time point.
 
static double compute_time_diff (const TimePointType &rtp, const TimePointType &ltp, const Precision &precision)
 
static double elapsed (const TimePointType &tp, const Precision &precision=Precision::Milliseconds)
 
static double delta (const TimePointType &tp, const Precision &precision=Precision::Milliseconds)
 

Detailed Description

Class Now is a practical class for timing based in a high resolution clock.

An instance of this class allows to measure elapsed time between two instants.

Usage example:

Now now;
now.start();
// Any block of code
cout << "Time elapsed: " << now.elapsed() << "ms\n";

Furthermore you may use the static methods just like that:

// Any block of code
cout << "Time elapsed: " << Now::elapsed(t) << "ms\n";
Author
Alejandro J. Mujica

Constructor & Destructor Documentation

◆ Now() [1/2]

Aleph::Now::Now ( bool  start_now = false)
inline

Builds a new object with default values.

Builds a new object with default time point and precision in MILLISECONDS. You may set the object to start counting time immediately by setting the parameter start_now in true. This constructor can be used as parametric or default.

Parameters
start_nowIf true, then the object starts counting the time immediately. By default is false.
See also
Precision

◆ Now() [2/2]

Aleph::Now::Now ( const Precision _precision,
bool  start_now = false 
)
inline

Builds a new object with parametric precision time.

Builds a new object with default time point and precision given as a parameter. You may set the object to start counting time immediately by setting the parameter start_now in true.

Parameters
_precisionThe type of precision for timing.
start_nowIf true, then the object starts counting the time immediately. By default is false.
See also
Precision

Member Function Documentation

◆ compute_time_diff()

static double Aleph::Now::compute_time_diff ( const TimePointType &  rtp,
const TimePointType &  ltp,
const Precision precision 
)
inlinestatic

Calculates the time that has elapsed between two time points.

Parameters
rtpRight time point.
ltpLeft time point.
precisionType of precision for calculating the time.
Returns
The time calculated.
See also
Precision

◆ delta() [1/2]

double Aleph::Now::delta ( )
inline

Like elapsed().

See also
elapsed().

◆ delta() [2/2]

static double Aleph::Now::delta ( const TimePointType &  tp,
const Precision precision = Precision::Milliseconds 
)
inlinestatic

Like elapsed(const TimePointType & tp, const Precision & precision = MILLISECONDS).

See also
elapsed(const TimePointType & tp, const Precision & precision = MILLISECONDS)

◆ elapsed() [1/2]

double Aleph::Now::elapsed ( )
inline

Calculates the time that has elapsed since the last time start(), elapsed() or delta() was called.

The value calculated depends of precision.

Returns
The time calculated.
See also
start(), delta(), Precision

◆ elapsed() [2/2]

static double Aleph::Now::elapsed ( const TimePointType &  tp,
const Precision precision = Precision::Milliseconds 
)
inlinestatic

Calculates the time that has elapsed since a given time point.

This is a class method. It's useful when is required massive time calculations and is not desired massive object instances of Now.

Parameters
tpTime point from which you want to calculate.
precisionThe type of precision for timing, by default is MILLISECONDS.
Returns
The time calculated.
See also
Precision

◆ get_precision()

const Precision& Aleph::Now::get_precision ( ) const
inline

Gets the type of precision.

See also
Precision

◆ set_precision()

void Aleph::Now::set_precision ( const Precision _precision)
inline

Sets the type of precision.

See also
Precision

◆ start()

TimePointType Aleph::Now::start ( )
inline

Sets internally the current time point.

This method must be used before calling elapsed() or delta() the first time.

Returns
The current time point.
See also
current_time_point()

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

Leandro Rabindranath León