Radium Engine  1.5.20
Loading...
Searching...
No Matches
Ra::Core::Utils::Chrono Class Reference

The Chrono class represents a chronometer for timing generic functions in an easy way. More...

#include <Core/Utils/Chronometer.hpp>

+ Collaboration diagram for Ra::Core::Utils::Chrono:

Public Types

using MicroSeconds = long
 
using Seconds = Scalar
 

Public Member Functions

 Chrono ()
 Default constructor.
 
 Chrono (const Chrono &other)=default
 Copy constructor.
 
 Chrono (Chrono &&other)=default
 Move constructor.
 
 ~Chrono ()
 Destructor.
 
template<class Function , class... Args>
void run (Function &&f, Args &&... args)
 Run the given void function f( args ... ) and times it.
 
template<typename ReturnType , class Function , class... Args>
ReturnType run (Function &&f, Args... args)
 Run the given ReturnType function f( args ... ) and times it.
 
template<std::size_t Times, class Function , class... Args>
MicroSeconds test (Function &&f, Args &&... args)
 Run the given function f( args ... ) n Times and compute the average timing.
 
MicroSeconds elapsedMicroSeconds () const
 Return the elapsed time for last call of run in microseconds.
 
Seconds elapsedSeconds () const
 Return the elapsed time for last call of run in seconds.
 
Chronooperator= (const Chrono &other)=default
 Copy assignment operator.
 
Chronooperator= (Chrono &&other)=default
 Move assignment operator.
 
bool operator== (const Chrono &other) const
 Equal operator.
 
bool operator< (const Chrono &other) const
 Less operator.
 

Protected Attributes

TimePoint m_start
 VARIABLE.
 
TimePoint m_end
 Time after running the function.
 

Detailed Description

The Chrono class represents a chronometer for timing generic functions in an easy way.

!

Example:

 void foo( foo_args ... ) { ... }
 some_type bar( bar_args ... ) { ... }

 Chrono foo_time;
 foo_time.run( foo, foo_args... );

 Chrono bar_time;
 some_type bar_result = bar_time< same_type >.run( bar, foo_args... );

 if( foo_time == bar_time ) {
     std::cout << "time is equal";
 } else {
     if( foo_time < bar_time ) {
         std::cout << "foo is faster";
     } else {
         std::cout << "bar is faster";
     }
 }
Note
Note that bar( bar_args ...) == bar_time< same_type >.run( bar, bar_args... )
See also
Ra::Core::Utils::getIntervalMicro
Ra::Core::Utils::getIntervalSeconds

Definition at line 38 of file Chronometer.hpp.

Member Typedef Documentation

◆ MicroSeconds

using Ra::Core::Utils::Chrono::MicroSeconds = long

Definition at line 41 of file Chronometer.hpp.

◆ Seconds

using Ra::Core::Utils::Chrono::Seconds = Scalar

Definition at line 42 of file Chronometer.hpp.

Constructor & Destructor Documentation

◆ Chrono()

Ra::Core::Utils::Chrono::Chrono ( )
inline

Default constructor.

Definition at line 46 of file Chronometer.hpp.

◆ ~Chrono()

Ra::Core::Utils::Chrono::~Chrono ( )
inline

Destructor.

Definition at line 61 of file Chronometer.hpp.

Member Function Documentation

◆ elapsedMicroSeconds()

MicroSeconds Ra::Core::Utils::Chrono::elapsedMicroSeconds ( ) const
inline

Return the elapsed time for last call of run in microseconds.

!

Returns
The elapsed time in microseconds.
See also
Ra::Core::Utils::getIntervalMicro

Definition at line 125 of file Chronometer.hpp.

◆ elapsedSeconds()

Seconds Ra::Core::Utils::Chrono::elapsedSeconds ( ) const
inline

Return the elapsed time for last call of run in seconds.

!

Returns
The elapsed time in seconds.
See also
Ra::Core::Utils::getIntervalSeconds

Definition at line 132 of file Chronometer.hpp.

◆ operator<()

bool Ra::Core::Utils::Chrono::operator< ( const Chrono & other) const
inline

Less operator.

!

Definition at line 154 of file Chronometer.hpp.

+ Here is the call graph for this function:

◆ operator=() [1/2]

Chrono & Ra::Core::Utils::Chrono::operator= ( Chrono && other)
inlinedefault

Move assignment operator.

!

◆ operator=() [2/2]

Chrono & Ra::Core::Utils::Chrono::operator= ( const Chrono & other)
inlinedefault

Copy assignment operator.

!

◆ operator==()

bool Ra::Core::Utils::Chrono::operator== ( const Chrono & other) const
inline

Equal operator.

!

Definition at line 147 of file Chronometer.hpp.

+ Here is the call graph for this function:

◆ run() [1/2]

template<class Function , class... Args>
void Ra::Core::Utils::Chrono::run ( Function && f,
Args &&... args )
inline

Run the given void function f( args ... ) and times it.

!

Parameters
fThe function to be timed.
argsThe parameters of f.
Template Parameters
FunctionType of the input function (automatically deduced)
ArgsVariadic pack with function parameters

Definition at line 71 of file Chronometer.hpp.

◆ run() [2/2]

template<typename ReturnType , class Function , class... Args>
ReturnType Ra::Core::Utils::Chrono::run ( Function && f,
Args... args )
inline

Run the given ReturnType function f( args ... ) and times it.

!

Parameters
fThe function to be timed.
argsThe parameters of f.
Template Parameters
TimesNumber of function run
FunctionType of the input function (automatically deduced)
ArgsVariadic pack with function parameters
Returns
The output of f( args ... ).

Definition at line 87 of file Chronometer.hpp.

◆ test()

template<std::size_t Times, class Function , class... Args>
MicroSeconds Ra::Core::Utils::Chrono::test ( Function && f,
Args &&... args )
inline

Run the given function f( args ... ) n Times and compute the average timing.

!

Parameters
fThe function to be timed.
argsThe parameters of f.
Template Parameters
TimesNumber of function run
FunctionType of the input function (automatically deduced)
ArgsVariadic pack with function parameters
Returns
The average time of f( args ... ) in microseconds.

Definition at line 106 of file Chronometer.hpp.

Member Data Documentation

◆ m_end

TimePoint Ra::Core::Utils::Chrono::m_end
protected

Time after running the function.

Definition at line 161 of file Chronometer.hpp.

◆ m_start

TimePoint Ra::Core::Utils::Chrono::m_start
protected

VARIABLE.

Time at the beginning of the function.

Definition at line 160 of file Chronometer.hpp.


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