Cogs.Core
Timer.Linux.cpp
1#include "Timer.h"
2
3#include <time.h>
4
5Cogs::TimePerf Cogs::perfTime() // Nanoseconds
6{
7 timespec t;
8 clock_gettime(CLOCK_MONOTONIC, &t);
9 return (static_cast<Cogs::TimePerf>(t.tv_sec) * 1000000000) + t.tv_nsec;
10}
11
12Cogs::Time Cogs::currentTime() // Nanoseconds
13{
14 timespec t;
15 clock_gettime(CLOCK_REALTIME, &t);
16 return (static_cast<Cogs::TimePerf>(t.tv_sec) * 1000000000) + t.tv_nsec;
17}
18
19int64_t Cogs::perfTimeToMicroseconds(TimePerf time)
20{
21 return time / 1000;
22}
23int64_t Cogs::perfTimeToMilliseconds(TimePerf time)
24{
25 return time / 1000000;
26}
27double Cogs::perfTimeToSeconds(TimePerf time)
28{
29 return time / 1000000000.0;
30}
31
32int64_t Cogs::currentTimeToMicroseconds(Time time)
33{
34 return time / 1000;
35}
36int64_t Cogs::currentTimeToMilliseconds(Time time)
37{
38 return time / 1000000;
39}
40double Cogs::currentTimeToSeconds(Time time)
41{
42 return time / 1000000000.0;
43}
COGSFOUNDATION_API int64_t perfTimeToMicroseconds(TimePerf time)
Convertion functions for timestamps.
COGSFOUNDATION_API TimePerf perfTime()
High resolution performance timer. Returns an implementation defined absolute timestamp,...
COGSFOUNDATION_API Time currentTime()
High resolution clock time (NTP / UTC time). Returns an implementation defined absolute timestamp,...