Bayes Filters Library
Public Member Functions | Private Attributes | List of all members
bfl::utils::CpuTimer< timetype > Class Template Reference

This template class provides methods to keep track of time. More...

#include <utils.h>

Public Member Functions

void start ()
 Start the timer. More...
 
void stop ()
 Stop the timer. More...
 
double elapsed ()
 Get the time passed between a start() and stop() call. More...
 
double now ()
 Get the absolute time from epoch. More...
 
bool is_running ()
 Check if the timer is running or not. More...
 

Private Attributes

std::chrono::steady_clock::time_point start_time_ = std::chrono::steady_clock::now()
 The start time. More...
 
std::chrono::steady_clock::time_point stop_time_ = start_time_
 The stop time. More...
 
bool running_ = false
 Running status flag. More...
 

Detailed Description

template<typename timetype = std::chrono::milliseconds>
class bfl::utils::CpuTimer< timetype >

This template class provides methods to keep track of time.

The default time unit is milliseconds, but can be changed during object creation using a different std::chrono::duration type. See https://en.cppreference.com/w/cpp/chrono/duration for reference. The timer starts and stops using, respectively, start() and stop() method. The get the time elapsed between a start() and stop() call, use the elapsed() method. The elapsed() method can be used to get the elapsed time from the start() call, before calling stop(). To get the absolute time from epoch use the now() method.

Definition at line 463 of file utils.h.

Member Function Documentation

◆ elapsed()

template<typename timetype = std::chrono::milliseconds>
double bfl::utils::CpuTimer< timetype >::elapsed ( )
inline

Get the time passed between a start() and stop() call.

If used between a start() and stop() call, returns the time elapsed from the start() call.

Returns
The elapsed time.

Definition at line 494 of file utils.h.

References bfl::utils::CpuTimer< timetype >::running_, bfl::utils::CpuTimer< timetype >::start_time_, and bfl::utils::CpuTimer< timetype >::stop_time_.

Referenced by bfl::TimeDecreasingDynamics::setProperty().

◆ is_running()

template<typename timetype = std::chrono::milliseconds>
bool bfl::utils::CpuTimer< timetype >::is_running ( )
inline

Check if the timer is running or not.

Returns
True/false if the timer is running/not running.

Definition at line 523 of file utils.h.

References bfl::utils::CpuTimer< timetype >::running_.

Referenced by bfl::TimeDecreasingDynamics::setProperty().

◆ now()

template<typename timetype = std::chrono::milliseconds>
double bfl::utils::CpuTimer< timetype >::now ( )
inline

Get the absolute time from epoch.

Returns
The elapsed time from epoch.

Definition at line 512 of file utils.h.

◆ start()

template<typename timetype = std::chrono::milliseconds>
void bfl::utils::CpuTimer< timetype >::start ( )
inline

◆ stop()

template<typename timetype = std::chrono::milliseconds>
void bfl::utils::CpuTimer< timetype >::stop ( )
inline

Member Data Documentation

◆ running_

template<typename timetype = std::chrono::milliseconds>
bool bfl::utils::CpuTimer< timetype >::running_ = false
private

◆ start_time_

template<typename timetype = std::chrono::milliseconds>
std::chrono::steady_clock::time_point bfl::utils::CpuTimer< timetype >::start_time_ = std::chrono::steady_clock::now()
private

The start time.

Definition at line 532 of file utils.h.

Referenced by bfl::utils::CpuTimer< timetype >::elapsed(), and bfl::utils::CpuTimer< timetype >::start().

◆ stop_time_

template<typename timetype = std::chrono::milliseconds>
std::chrono::steady_clock::time_point bfl::utils::CpuTimer< timetype >::stop_time_ = start_time_
private

The stop time.

Definition at line 538 of file utils.h.

Referenced by bfl::utils::CpuTimer< timetype >::elapsed(), and bfl::utils::CpuTimer< timetype >::stop().


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