Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Now Class Reference

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

#include <ahNow.H>

Public Types

enum class  Precision {
  Hours , Minutes , Seconds , Milliseconds ,
  Microseconds , Nanoseconds
}
 Precision for timing. More...
 
using ClockType = std::chrono::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.
 
 Now (const Precision &_precision, bool start_now=false)
 Builds a new object with parametric precision time.
 
const Precisionget_precision () const
 Gets the type of precision.
 
void set_precision (const Precision &_precision)
 Sets the type of precision.
 
TimePointType start ()
 Sets internally the current time point.
 
double elapsed ()
 Calculates the time that has elapsed since the last time start(), elapsed() or delta() was called.
 
double delta ()
 Like elapsed().
 

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)
 Calculates the time that has elapsed between two time points.
 
static double elapsed (const TimePointType &tp, const Precision &precision=Precision::Milliseconds)
 Calculates the time that has elapsed since a given time point.
 
static double delta (const TimePointType &tp, const Precision &precision=Precision::Milliseconds)
 Like elapsed(const TimePointType & tp, const Precision & precision = MILLISECONDS).
 

Private Attributes

TimePointType tp
 
Precision precision
 

Static Private Attributes

static const double precision_values []
 

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.start();
// Any block of code
std::cout << "Time elapsed: " << now.elapsed() << "ms\n";
Class Now is a practical class for timing based in a high resolution clock.
Definition ahNow.H:79
DynList< T > maps(const C &c, Op op)
Classic map operation.

Furthermore you may use the static methods just like that:

// Any block of code
std::cout << "Time elapsed: " << Now::elapsed(t) << "ms\n";
static TimePointType current_time_point()
Gets the current time point.
Definition ahNow.H:110
double elapsed()
Calculates the time that has elapsed since the last time start(), elapsed() or delta() was called.
Definition ahNow.H:209
Author
Alejandro J. Mujica

Definition at line 78 of file ahNow.H.

Member Typedef Documentation

◆ ClockType

using Aleph::Now::ClockType = std::chrono::high_resolution_clock

Definition at line 97 of file ahNow.H.

◆ DurationType

using Aleph::Now::DurationType = ClockType::duration

Definition at line 99 of file ahNow.H.

◆ TimePointType

using Aleph::Now::TimePointType = ClockType::time_point

Definition at line 98 of file ahNow.H.

Member Enumeration Documentation

◆ Precision

Precision for timing.

Enumerator
Hours 
Minutes 
Seconds 
Milliseconds 
Microseconds 
Nanoseconds 

Definition at line 82 of file ahNow.H.

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

Definition at line 143 of file ahNow.H.

References Aleph::maps(), and start().

◆ 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

Definition at line 162 of file ahNow.H.

References Aleph::maps(), and start().

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

Definition at line 123 of file ahNow.H.

References Aleph::maps(), precision, precision_values, and to_int().

Referenced by elapsed(), and elapsed().

◆ current_time_point()

static TimePointType Aleph::Now::current_time_point ( )
inlinestatic

Gets the current time point.

Definition at line 110 of file ahNow.H.

Referenced by elapsed(), elapsed(), and start().

◆ delta() [1/2]

double Aleph::Now::delta ( )
inline

Like elapsed().

See also
elapsed().

Definition at line 220 of file ahNow.H.

References 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)

Definition at line 248 of file ahNow.H.

References elapsed(), precision, and tp.

◆ 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

Definition at line 209 of file ahNow.H.

References compute_time_diff(), current_time_point(), Aleph::maps(), precision, and tp.

Referenced by delta(), and delta().

◆ 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

Definition at line 236 of file ahNow.H.

References compute_time_diff(), current_time_point(), precision, and tp.

◆ get_precision()

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

Gets the type of precision.

See also
Precision

Definition at line 173 of file ahNow.H.

References precision.

◆ set_precision()

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

Sets the type of precision.

See also
Precision

Definition at line 182 of file ahNow.H.

References Aleph::maps(), and 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()

Definition at line 195 of file ahNow.H.

References current_time_point(), and tp.

Referenced by Now(), and Now().

◆ to_int()

static int Aleph::Now::to_int ( Precision  p)
inlinestatic

Definition at line 92 of file ahNow.H.

Referenced by compute_time_diff().

Member Data Documentation

◆ precision

Precision Aleph::Now::precision
private

Definition at line 104 of file ahNow.H.

Referenced by compute_time_diff(), delta(), elapsed(), elapsed(), get_precision(), and set_precision().

◆ precision_values

const double Aleph::Now::precision_values
staticprivate
Initial value:
=
{ 1e-9 / 3600, 1e-9 / 60, 1e-9, 1e-6, 1e-3, 1.0 }

Definition at line 35 of file ahNow.H.

Referenced by compute_time_diff().

◆ tp

TimePointType Aleph::Now::tp
private

Definition at line 102 of file ahNow.H.

Referenced by delta(), elapsed(), elapsed(), and start().


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