Turi Create
4.0
|
A simple class that can be used for benchmarking/timing up to microsecond resolution. More...
#include <core/system/platform/timer/timer.hpp>
Public Member Functions | |
timer () | |
The timer starts on construction but can be restarted by calling turi::timer::start. | |
void | start () |
Reset the timer. | |
double | current_time () const |
Returns the elapsed time in seconds since turi::timer::start was last called. More... | |
double | current_time_millis () const |
Returns the elapsed time in milliseconds since turi::timer::start was last called. More... | |
Static Public Member Functions | |
static double | sec_of_day () |
Get the number of seconds (as a floating point value) since the Unix Epoch. | |
static size_t | usec_of_day () |
Returns only the micro-second component of the time since the Unix Epoch. | |
static float | approx_time_seconds () |
Returns the time since program start. More... | |
static size_t | approx_time_millis () |
Returns the time since program start. More... | |
static void | stop_approx_timer () |
Stops the approximate timer. More... | |
static void | sleep (size_t sleeplen) |
static void | sleep_ms (size_t sleeplen) |
A simple class that can be used for benchmarking/timing up to microsecond resolution.
The timer is used by calling turi::timer::start and then by getting the current time since start by calling turi::timer::current_time.
For example:
The sleep routines here are preferred than the sleep method provided by the standard C library. On Linux, the C sleep method can be woken up by signals, hence it may not sleep the full prescribed interval. The sleep implemented in the timer are more resilient.
Calling current item in a tight loop can be costly and so we provide a faster less accurate timing primitive which reads a local time variable that is updated roughly every 100 millisecond. These are the turi::timer::approx_time_seconds and turi::timer::approx_time_millis.
|
static |
Returns the time since program start.
This value is only updated once every 100ms and is therefore approximate (but fast).
|
static |
Returns the time since program start.
This value is only updated once every 100ms and is therefore approximate (but fast).
|
inline |
Returns the elapsed time in seconds since turi::timer::start was last called.
|
inline |
Returns the elapsed time in milliseconds since turi::timer::start was last called.
|
static |
Sleeps for sleeplen seconds
|
static |
Sleeps for sleeplen milliseconds.
|
static |
Stops the approximate timer.
This stops the approximate timer thread. Once stoped, the approximate time will never be advanced again. This function should not generally be used, but it seems like on certain platforms (windows for instance) it does not like terminating threads inside DLLs at program terminiation. This can be used to force thread termination.