From f19f50a744751e469d0956dde47e16da0ae58926 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Thu, 27 Jul 2023 06:08:40 +0000 Subject: [PATCH] stylistic changes for the windows support ifdefs --- run.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/run.c b/run.c index d1e3d2a..80b0b00 100644 --- a/run.c +++ b/run.c @@ -14,13 +14,12 @@ $ ./run #include #include #include -#ifndef _WIN32 -#include -#include +#if defined _WIN32 + #include "win.h" #else -#include "win.h" -#endif - + #include + #include +#endif // ---------------------------------------------------------------------------- // Transformer and RunState structs, and related memory management @@ -366,17 +365,14 @@ int argmax(float* v, int n) { // ---------------------------------------------------------------------------- long time_in_ms() { -#ifndef _WIN32 - struct timespec time; - // Get the current time with nanosecond precision - if (clock_gettime(CLOCK_REALTIME, &time) == 0) { - return time.tv_sec * 1000 + time.tv_nsec / 1000000; - } else { - perror("clock_gettime"); - return -1; // Return -1 to indicate an error - } -#else +#if defined _WIN32 + // windows specific way to get time return GetTickCount(); +#else + // linux specific way to get time + struct timespec time; + clock_gettime(CLOCK_REALTIME, &time); + return time.tv_sec * 1000 + time.tv_nsec / 1000000; #endif }