Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Timer Class Reference

The Timer class allows to instantiate simple Timer objects that can be used everywhere. More...

#include <vclib/base/timer.h>

Public Member Functions

double delay () const
 Returns the time passed between the call of start() and this member function. Works also if the timer is not stopped. Returned time is expressed in seconds.
 
void print () const
 Prints the time passed between the call of start() and this member function. Works also if the timer is not stopped. Printed time is expressed in seconds.
 
void setCaption (const std::string &caption)
 Sets the caption of the timer.
 
void start ()
 Starts the timer.
 
void stop ()
 Stops the timer.
 
void stopAndPrint ()
 Stops the timer and prints the time passed between the call of start() and this member function. Printed time is expressed in seconds.
 
 Timer (bool _start=true)
 Creates a timer with the caption "Timer". If the given boolean is true, the timer starts.
 
 Timer (const char *caption, bool _start=true)
 Creates a timer with the given caption. If the given boolean is true, the timer starts.
 
 Timer (const std::string &caption, bool _start=true)
 Creates a timer with the given caption. If the given boolean is true, the timer starts.
 

Private Attributes

std::chrono::high_resolution_clock::time_point mBegin
 
std::string mCaption = "Timer"
 
std::chrono::high_resolution_clock::time_point mEnd
 
bool mIsStopped = false
 

Detailed Description

The Timer class allows to instantiate simple Timer objects that can be used everywhere.

When a Timer object is create, by default the timer starts (you can change this option using the bool argument of the Timer constructor). To each timer can be associated a caption, and the printed/returned values are expressed in seconds.

Constructor & Destructor Documentation

◆ Timer() [1/3]

vcl::Timer::Timer ( bool  _start = true)
inline

Creates a timer with the caption "Timer". If the given boolean is true, the timer starts.

Parameters
[in]_startif true, the timer will start when the object is created.

◆ Timer() [2/3]

vcl::Timer::Timer ( const char caption,
bool  _start = true 
)
inline

Creates a timer with the given caption. If the given boolean is true, the timer starts.

Parameters
[in]captionthe caption of the timer.
[in]_startif true, the timer will start when the object is created.

◆ Timer() [3/3]

vcl::Timer::Timer ( const std::string &  caption,
bool  _start = true 
)
inline

Creates a timer with the given caption. If the given boolean is true, the timer starts.

Parameters
[in]captionthe caption of the timer.
[in]_startif true, the timer will start when the object is created.

Member Function Documentation

◆ setCaption()

void vcl::Timer::setCaption ( const std::string &  caption)
inline

Sets the caption of the timer.

Parameters
[in]captionthe new caption of the timer.

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