The library also provides a small timer utility that can be used to record how long a piece of code takes to execute.
C++ API
In the C++ API, the Timer
class is used. It looks like
this:
class MLS_PUBLIC_API Timer
{
public:
void start() noexcept;
void stop() noexcept;
[[nodiscard]] double get() const noexcept;
};
As you can see the functions are self-explanatory.
Tip
To reuse timers, you can just call start
after calling
stop
. This will reset the timer, as stop
does
not reset the timer and only records the time since the start of the
recording
Tip
To periodically check on the same timer, call stop
, then
get
. The stop
function just captures the time
since the start of the recording and does not reset the timer.
C API
The C API is almost identical, as it is just a light wrapper. It looks like this:
struct ULog_Timer{...};
void ULog_Timer_start(ULog_Timer* timer);
void ULog_Timer_stop(ULog_Timer* timer);
double ULog_Timer_get(ULog_Timer* timer);
As you can see the functions are the same, the only difference is in
the naming and the fact that you have to create an instance of the
ULog_Timer
struct, which you have to pass to the
functions.