Cogs.Core
Timer.Emscripten.cpp
1#include "Timer.h"
2
3#include <time.h>
4#include <emscripten/emscripten.h>
5
6Cogs::TimePerf Cogs::perfTime() // Milliseconds
7{
8 return emscripten_get_now();
9}
10
11Cogs::Time Cogs::currentTime() // Nanoseconds
12{
13 timespec t;
14 clock_gettime(CLOCK_REALTIME, &t);
15 return (t.tv_sec * 1000000000) + t.tv_nsec;
16}
17
18int64_t Cogs::perfTimeToMicroseconds(TimePerf time)
19{
20 return time * 1000;
21}
22int64_t Cogs::perfTimeToMilliseconds(TimePerf time)
23{
24 return time;
25}
26double Cogs::perfTimeToSeconds(TimePerf time)
27{
28 return time / 1000.0;
29}
30
31int64_t Cogs::currentTimeToMicroseconds(Time time)
32{
33 return time / 1000;
34}
35int64_t Cogs::currentTimeToMilliseconds(Time time)
36{
37 return time / 1000000;
38}
39double Cogs::currentTimeToSeconds(Time time)
40{
41 return time / 1000000000.0;
42}
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,...