commit 78c2f3cb1e12ecc3b5a85602293625022e5cca44 parent fd14a29656146cbb49fbc7bfa9adff9b6444d12a Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Jan 18 23:51:30 +0200 Add platform_time.h Diffstat:
platform_time.h | | | 13 | +++++++++++++ |
unix_time.h | | | 10 | ++++++++++ |
win32_time.h | | | 13 | +++++++++++++ |
diff --git a/platform_time.h b/platform_time.h @@ -0,0 +1,13 @@ +#pragma once + +#include "platform.h" + +#if PLATFORM_WINDOWS +#include "win32_time.h" +#elif PLATFORM_OSX +#include "darwin_time.h" +#elif PLATFORM_UNIX +#include "unix_time.h" +#else +#error new platform +#endif diff --git a/unix_time.h b/unix_time.h @@ -0,0 +1,10 @@ +#pragma once + +#include <time.h> + +inline double get_time() { + struct timespec ts; + clock_gettime( CLOCK_MONOTONIC, &ts ); + + return double( ts.tv_sec ) + ts.tv_nsec / 1000000000.0; +} diff --git a/win32_time.h b/win32_time.h @@ -0,0 +1,13 @@ +#pragma once + +#include <windows.h> + +inline double get_time() { + LARGE_INTEGER counter; + QueryPerformanceCounter( &counter ); + + LARGE_INTEGER freq; + QueryPerformanceFrequency( &freq ); + + return double( counter.QuadPart ) / double( freq.QuadPart ); +}