NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
Public Types | Public Member Functions | List of all members
BiometricEvaluation::Time::Timer Class Reference

This class can be used by applications to report the amount of time a block of code takes to execute. More...

#include <be_time_timer.h>

Public Types

using BE_CLOCK_TYPE = std::chrono::steady_clock
 Clock type to use, aliased for easy replacement. More...
 

Public Member Functions

 Timer ()
 Constructor for the Timer object. More...
 
 Timer (const std::function< void()> &func)
 Construct a timer and time a function immediately. More...
 
void start ()
 Start tracking time. More...
 
void stop ()
 Stop tracking time. More...
 
uint64_t elapsed (bool nano=false) const
 Get the elapsed time in microseconds or nanoseconds between calls to this object's start() and stop() methods. More...
 
std::string elapsedStr (bool displayUnits=false, bool nano=false) const
 Convenience method for printing elapsed time as a string. More...
 
Timertime (const std::function< void()> &func)
 Record the runtime of a function. More...
 

Detailed Description

This class can be used by applications to report the amount of time a block of code takes to execute.

Applcations wrap the block of code in the Timer::start() and Timer::stop() calls, then use Timer::elapsed() to obtain the calculated time of the operation.

Warning
Timers are not threadsafe and should only be used to time operations within the same thread.

Definition at line 38 of file be_time_timer.h.

Member Typedef Documentation

◆ BE_CLOCK_TYPE

using BiometricEvaluation::Time::Timer::BE_CLOCK_TYPE = std::chrono::steady_clock

Clock type to use, aliased for easy replacement.

Definition at line 42 of file be_time_timer.h.

Constructor & Destructor Documentation

◆ Timer() [1/2]

BiometricEvaluation::Time::Timer::Timer ( )

Constructor for the Timer object.

◆ Timer() [2/2]

BiometricEvaluation::Time::Timer::Timer ( const std::function< void()> &  func)

Construct a timer and time a function immediately.

Parameters
funcA function to time immediately.
Exceptions
Error::StrategyErrorPropagated from time().

Member Function Documentation

◆ start()

void BiometricEvaluation::Time::Timer::start ( )

Start tracking time.

Exceptions
Error::StrategyErrorThis object is currently timing an operation or an error occurred when obtaining timing information.

◆ stop()

void BiometricEvaluation::Time::Timer::stop ( )

Stop tracking time.

Exceptions
Error::StrategyErrorThis object is not currently timing an operation or an error occurred when obtaining timing information.

◆ elapsed()

uint64_t BiometricEvaluation::Time::Timer::elapsed ( bool  nano = false) const

Get the elapsed time in microseconds or nanoseconds between calls to this object's start() and stop() methods.

Parameters
nanoTrue if to return nanoseconds, false otherwise.
Returns
The number of microseconds or nanoseconds.
Exceptions
Error::StrategyErrorThis object is currently timing an operation or an error occurred when obtaining timing information.

◆ elapsedStr()

std::string BiometricEvaluation::Time::Timer::elapsedStr ( bool  displayUnits = false,
bool  nano = false 
) const

Convenience method for printing elapsed time as a string.

Parameters
displayUnitsAppend the elapsed time units.
nanoTrue if to return nanoseconds, false otherwise.
Returns
String representing the elapsed time.
Exceptions
Error::StrategyErrorPropagated from elapsed().

◆ time()

Timer & BiometricEvaluation::Time::Timer::time ( const std::function< void()> &  func)

Record the runtime of a function.

Parameters
funcFunction to time.
Returns
Reference to this class.
Exceptions
Error::StrategyErrorPropagated from start() or stop(), and/or func is nullptr.

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