diff options
author | Jacek Sieka <arnetheduck@gmail.com> | 2019-07-13 08:39:20 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-07-13 08:39:20 +0200 |
commit | cf36e4a44a0436ae8b798311ced2e20f513e12d9 (patch) | |
tree | 6be12d9cab6afe42d5eca553ed0d18235cc36472 /lib/pure | |
parent | de1ede77fe91170269d5bf54a01e61ff95f6dc56 (diff) | |
download | Nim-cf36e4a44a0436ae8b798311ced2e20f513e12d9.tar.gz |
times: use posix constant instead of import (#11692)
* times: use posix constant instead of import * simplify clock id usage
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/times.nim | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 7550a8dea..c199643ec 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -221,11 +221,6 @@ elif defined(posix): type CTime = posix.Time - var - realTimeClockId {.importc: "CLOCK_REALTIME", header: "<time.h>".}: ClockId - cpuClockId - {.importc: "CLOCK_THREAD_CPUTIME_ID", header: "<time.h>".}: ClockId - when not defined(freebsd) and not defined(netbsd) and not defined(openbsd): var timezone {.importc, header: "<time.h>".}: int when not defined(valgrind_workaround_10121): @@ -1205,7 +1200,7 @@ proc getTime*(): Time {.tags: [TimeEffect], benign.} = convert(Microseconds, Nanoseconds, a.tv_usec.int)) elif defined(posix): var ts: Timespec - discard clock_gettime(realTimeClockId, ts) + discard clock_gettime(CLOCK_REALTIME, ts) result = initTime(ts.tv_sec.int64, ts.tv_nsec.int) elif defined(windows): var f: FILETIME @@ -2509,11 +2504,11 @@ when not defined(JS): fib.add(fib[^1] + fib[^2]) echo "CPU time [s] ", cpuTime() - t0 echo "Fib is [s] ", fib - when defined(posix) and not defined(osx): + when defined(posix) and not defined(osx) and declared(CLOCK_THREAD_CPUTIME_ID): # 'clocksPerSec' is a compile-time constant, possibly a # rather awful one, so use clock_gettime instead var ts: Timespec - discard clock_gettime(cpuClockId, ts) + discard clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts) result = toFloat(ts.tv_sec.int) + toFloat(ts.tv_nsec.int) / 1_000_000_000 else: @@ -2531,7 +2526,7 @@ when not defined(JS): result = toBiggestFloat(a.tv_sec.int64) + toBiggestFloat(a.tv_usec)*0.00_0001 elif defined(posix): var ts: Timespec - discard clock_gettime(realTimeClockId, ts) + discard clock_gettime(CLOCK_REALTIME, ts) result = toBiggestFloat(ts.tv_sec.int64) + toBiggestFloat(ts.tv_nsec.int64) / 1_000_000_000 elif defined(windows): |