M src/core/util.c => src/core/util.c +6 -4
@@ 892,11 892,13 @@ int janet_gettime(struct timespec *spec, enum JanetTimeSource source) {
QueryPerformanceCounter(&count);
QueryPerformanceFrequency(&perf_freq);
spec->tv_sec = count.QuadPart / perf_freq.QuadPart;
- spec->tv_nsec = (count.QuadPart % perf_freq.QuadPart) * 1000000000 / perf_freq.QuadPart;
+ spec->tv_nsec = (long)((count.QuadPart % perf_freq.QuadPart) * 1000000000 / perf_freq.QuadPart);
} else if (source == JANET_TIME_CPUTIME) {
- float tmp = clock();
- spec->tv_sec = tmp / CLOCKS_PER_SEC;
- spec->tv_nsec = (tmp - spec->tv_sec * CLOCKS_PER_SEC) * 1e9 / CLOCKS_PER_SEC;
+ FILETIME creationTime, exitTime, kernelTime, userTime;
+ GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime);
+ int64_t tmp = ((int64_t)userTime.dwHighDateTime << 32) + userTime.dwLowDateTime;
+ spec->tv_sec = tmp / 10000000LL;
+ spec->tv_nsec = tmp % 10000000LL * 100;
}
return 0;
}
M test/suite0007.janet => test/suite0007.janet +4 -4
@@ 334,16 334,16 @@
(assert (pos? (length (gensym))) "gensym not empty, regression #753")
-# os/clock
+# os/clock. These tests might prove fragile under CI because they
+# rely on measured time. We'll see.
(defmacro measure-time [clocks & body]
- (def t1 (gensym))
- (def t2 (gensym))
+ (def [t1 t2] [(gensym) (gensym)])
~(do
(def ,t1 (map |(os/clock $) ,clocks))
,;body
(def ,t2 (map |(os/clock $) ,clocks))
- (zipcoll ,clocks [ (- (,t2 0) (,t1 0)) (- (,t2 1) (,t1 1)) (- (,t2 2) (,t1 2))]))
+ (zipcoll ,clocks (map |(- ;$) (map tuple ,t2 ,t1))))
)
# Spin for 0.1 seconds