From d5433c348b4f73d2aaec5f0c47d5239657daf333 Mon Sep 17 00:00:00 2001 From: Moss Date: Tue, 13 Sep 2022 01:54:44 -0400 Subject: [PATCH] Helper Functions: Added time_ms functions This function return the current time in miliseconds Source: https://stackoverflow.com/questions/2831841/how-to-get-the-time-in-milliseconds-in-c --- main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.cpp b/main.cpp index 03348a2..dd5e77f 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,29 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use return size * nmemb; } +#if defined(__WIN32__) + +#include + +msec_t time_ms(void) +{ + return timeGetTime(); +} + +#else + +#include + +long time_ms() +{ + timeval tv; + gettimeofday(&tv, nullptr); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +#endif + + int clear_icanon() { struct termios settings{};