mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Fixed :cputime because msdn does not implement clock() properly
This commit is contained in:
parent
80db682109
commit
30c47d685d
@ -892,11 +892,13 @@ int janet_gettime(struct timespec *spec, enum JanetTimeSource source) {
|
|||||||
QueryPerformanceCounter(&count);
|
QueryPerformanceCounter(&count);
|
||||||
QueryPerformanceFrequency(&perf_freq);
|
QueryPerformanceFrequency(&perf_freq);
|
||||||
spec->tv_sec = count.QuadPart / perf_freq.QuadPart;
|
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) {
|
} else if (source == JANET_TIME_CPUTIME) {
|
||||||
float tmp = clock();
|
FILETIME creationTime, exitTime, kernelTime, userTime;
|
||||||
spec->tv_sec = tmp / CLOCKS_PER_SEC;
|
GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime);
|
||||||
spec->tv_nsec = (tmp - spec->tv_sec * CLOCKS_PER_SEC) * 1e9 / CLOCKS_PER_SEC;
|
int64_t tmp = ((int64_t)userTime.dwHighDateTime << 32) + userTime.dwLowDateTime;
|
||||||
|
spec->tv_sec = tmp / 10000000LL;
|
||||||
|
spec->tv_nsec = tmp % 10000000LL * 100;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -334,16 +334,16 @@
|
|||||||
(assert (pos? (length (gensym))) "gensym not empty, regression #753")
|
(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]
|
(defmacro measure-time [clocks & body]
|
||||||
(def t1 (gensym))
|
(def [t1 t2] [(gensym) (gensym)])
|
||||||
(def t2 (gensym))
|
|
||||||
~(do
|
~(do
|
||||||
(def ,t1 (map |(os/clock $) ,clocks))
|
(def ,t1 (map |(os/clock $) ,clocks))
|
||||||
,;body
|
,;body
|
||||||
(def ,t2 (map |(os/clock $) ,clocks))
|
(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
|
# Spin for 0.1 seconds
|
||||||
|
Loading…
Reference in New Issue
Block a user