SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
HighResTimer Class Reference

High Resolution Timer class using C++11. More...

#include <HighResTimer.h>

Public Member Functions

 HighResTimer ()
 
void start ()
 
void stop ()
 
float elapsedTimeInSec ()
 
float elapsedTimeInMilliSec ()
 
int64_t elapsedTimeInMicroSec ()
 

Static Public Member Functions

static void callAfterSleep (int milliSec, const function< void(void)> &callbackFunc)
 

Private Attributes

HighResTimePoint _timePoint1
 high precision start time point More...
 
HighResTimePoint _timePoint2
 high precision end time point More...
 

Detailed Description

High Resolution Timer class using C++11.

High Resolution Timer that is able to measure the elapsed time with 1 micro-second accuracy.

Definition at line 30 of file HighResTimer.h.

Constructor & Destructor Documentation

◆ HighResTimer()

HighResTimer::HighResTimer ( )
inline

Definition at line 33 of file HighResTimer.h.

33 { _timePoint1 = HighResClock::now(); }
HighResTimePoint _timePoint1
high precision start time point
Definition: HighResTimer.h:54

Member Function Documentation

◆ callAfterSleep()

static void HighResTimer::callAfterSleep ( int  milliSec,
const function< void(void)> &  callbackFunc 
)
inlinestatic

Definition at line 41 of file HighResTimer.h.

42  {
43  // Create a thread that immediately sleeps the milliseconds
44  thread t([=]()
45  {
46  this_thread::sleep_for(chrono::milliseconds(milliSec));
47  callbackFunc(); });
48 
49  // detach the thread so that it can exist after the block
50  t.detach();
51  }

◆ elapsedTimeInMicroSec()

int64_t HighResTimer::elapsedTimeInMicroSec ( )
inline

Definition at line 39 of file HighResTimer.h.

39 { return duration_cast<microseconds>(HighResClock::now() - _timePoint1).count(); }

◆ elapsedTimeInMilliSec()

float HighResTimer::elapsedTimeInMilliSec ( )
inline

Definition at line 38 of file HighResTimer.h.

38 { return (float)((double)elapsedTimeInMicroSec() / 1000.0); }
int64_t elapsedTimeInMicroSec()
Definition: HighResTimer.h:39

◆ elapsedTimeInSec()

float HighResTimer::elapsedTimeInSec ( )
inline

Definition at line 37 of file HighResTimer.h.

37 { return (float)((double)elapsedTimeInMicroSec() / 1000000.0); }

◆ start()

void HighResTimer::start ( )
inline

Definition at line 35 of file HighResTimer.h.

35 { _timePoint1 = HighResClock::now(); }

◆ stop()

void HighResTimer::stop ( )
inline

Definition at line 36 of file HighResTimer.h.

36 { _timePoint2 = HighResClock::now(); }
HighResTimePoint _timePoint2
high precision end time point
Definition: HighResTimer.h:55

Member Data Documentation

◆ _timePoint1

HighResTimePoint HighResTimer::_timePoint1
private

high precision start time point

Definition at line 54 of file HighResTimer.h.

◆ _timePoint2

HighResTimePoint HighResTimer::_timePoint2
private

high precision end time point

Definition at line 55 of file HighResTimer.h.


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