From 2be7d7887bfc67d34d8d5b4d02cc6182f98d0b55 Mon Sep 17 00:00:00 2001 From: richinseattle Date: Mon, 24 Jul 2023 15:22:20 -0700 Subject: [PATCH 1/2] MSVC Compatibility fix for timer use clock() instead of gettimeofday() for cross-platform compatibility --- run.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/run.c b/run.c index 11af4dc..57635d4 100644 --- a/run.c +++ b/run.c @@ -13,7 +13,6 @@ $ ./run #include #include #include -#include // ---------------------------------------------------------------------------- // Transformer and RunState structs, and related memory management @@ -378,9 +377,7 @@ int argmax(float* v, int n) { // ---------------------------------------------------------------------------- long time_in_ms() { - struct timeval time; - gettimeofday(&time, NULL); - return time.tv_sec * 1000 + time.tv_usec / 1000; + return (1000 * clock()) / CLOCKS_PER_SEC; } int main(int argc, char *argv[]) { From b2857c6af250fb919514c3b7d8ecce0ad7e02bd5 Mon Sep 17 00:00:00 2001 From: richinseattle Date: Mon, 24 Jul 2023 16:31:38 -0700 Subject: [PATCH 2/2] Switch to using timespec_get() for cross OS compatibility --- run.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run.c b/run.c index 57635d4..a77f5cd 100644 --- a/run.c +++ b/run.c @@ -377,7 +377,9 @@ int argmax(float* v, int n) { // ---------------------------------------------------------------------------- long time_in_ms() { - return (1000 * clock()) / CLOCKS_PER_SEC; + struct timespec time; + timespec_get(&time, TIME_UTC); + return time.tv_sec * 1000 + time.tv_nsec / 1000000; } int main(int argc, char *argv[]) {