Documentation for OpenFLUID 2.2.0
openfluid::tools::Timer Class Reference

Detailed Description

Class to instanciate timers and measure durations between their starts and stops.

MyTimer.start();
// here is the code we want to measure the duration of execution
MyTimer.stop();
auto Duration = MyTimer.elapsed(); // e.g. 13536
std::string DurationStr = MyTimer.elapsedAsPrettyString(); // e.g. 13.536s
Definition: Timer.hpp:58
void stop()
Definition: Timer.hpp:100
long int elapsed()
Definition: Timer.hpp:148
std::string elapsedAsPrettyString()
Definition: Timer.hpp:169
void start()
Definition: Timer.hpp:87

#include <tools/Timer.hpp>

Public Member Functions

 Timer (bool AutoStart=false)
 
void start ()
 
void stop ()
 
void restart ()
 
void reset ()
 
bool isRunning ()
 
long int elapsed ()
 
std::string elapsedAsPrettyString ()
 

Static Public Member Functions

static void splitDuration (long int MSecsDuration, int &Days, int &Hours, int &Minutes, int &Seconds, int &MSecs)
 
static std::string getDurationAsPrettyString (long int MSecsDuration)
 

Constructor & Destructor Documentation

◆ Timer()

openfluid::tools::Timer::Timer ( bool  AutoStart = false)
inline

Constructs a timer (not started by default)

Parameters
[in]AutoStartIf true, the timer is automatically started when it is instanciated (false by default)

Member Function Documentation

◆ elapsed()

long int openfluid::tools::Timer::elapsed ( )
inline

Returns the duration of the timer in milliseconds. If the timer is stopped, it returns the duration between start and stop. If the timer is running, it returns the duration between start and the call of the elapsed() method.

Returns
True if timer is running

◆ elapsedAsPrettyString()

std::string openfluid::tools::Timer::elapsedAsPrettyString ( )
inline

Returns the elapsed time as a pretty string representing days, hours, minutes and decimal seconds.

Returns
the converted duration as a string

◆ getDurationAsPrettyString()

static std::string openfluid::tools::Timer::getDurationAsPrettyString ( long int  MSecsDuration)
inlinestatic

Returns the given duration as a pretty string representing days, hours, minutes and decimal seconds.

std::string DurationStr;
DurationStr = openfluid::tools::Timer::getDurationAsPrettyString(123456789); // "1d 10h 17m 36.789s"
DurationStr = openfluid::tools::Timer::getDurationAsPrettyString(12345678); // "3h 25m 45.678s"
DurationStr = openfluid::tools::Timer::getDurationAsPrettyString(123456); // "2m 3.456s"
static std::string getDurationAsPrettyString(long int MSecsDuration)
Definition: Timer.hpp:200
Parameters
[in]MSecsDurationthe duration in milliseconds
Returns
the converted duration as a string

◆ isRunning()

bool openfluid::tools::Timer::isRunning ( )
inline

Returns true if the timer is currently running

Returns
True if timer is running

◆ reset()

void openfluid::tools::Timer::reset ( )
inline

Stops and resets the timer. If the timer is currently running, the elapsed time is lost

◆ restart()

void openfluid::tools::Timer::restart ( )
inline

Restarts the timer (even if currently running)

◆ splitDuration()

static void openfluid::tools::Timer::splitDuration ( long int  MSecsDuration,
int &  Days,
int &  Hours,
int &  Minutes,
int &  Seconds,
int &  MSecs 
)
inlinestatic

Splits the given duration in milliseconds into days, hours, minutes, seconds and milliseconds.

Parameters
[in]MSecsDurationthe duration in milliseconds
[out]Daysthe number of days
[out]Hoursthe number of hours
[out]Minutesthe number of minutes
[out]Secondsthe number of seconds
[out]MSecsthe number of milliseconds

◆ start()

void openfluid::tools::Timer::start ( )
inline

Starts the timer (if not currently running)

◆ stop()

void openfluid::tools::Timer::stop ( )
inline

Stops the timer (if currently running)


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