times: use posix constant instead of import (#11692)

* times: use posix constant instead of import

* simplify clock id usage
This commit is contained in:
Jacek Sieka 2019-07-13 08:39:20 +02:00 • committed by Andreas Rumpf
commit cf36e4a44a
2 changed files with 4 additions and 12 deletions

View file

@ -26,9 +26,6 @@ when not defined(leanCompiler):
from magicsys import resetSysTypes from magicsys import resetSysTypes
proc codegenPass(g: ModuleGraph) =
registerPass g, cgenPass
proc semanticPasses(g: ModuleGraph) = proc semanticPasses(g: ModuleGraph) =
registerPass g, verbosePass registerPass g, verbosePass
registerPass g, semPass registerPass g, semPass

View file

@ -221,11 +221,6 @@ elif defined(posix):
type CTime = posix.Time 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): when not defined(freebsd) and not defined(netbsd) and not defined(openbsd):
var timezone {.importc, header: "<time.h>".}: int var timezone {.importc, header: "<time.h>".}: int
when not defined(valgrind_workaround_10121): when not defined(valgrind_workaround_10121):
@ -1205,7 +1200,7 @@ proc getTime*(): Time {.tags: [TimeEffect], benign.} =
convert(Microseconds, Nanoseconds, a.tv_usec.int)) convert(Microseconds, Nanoseconds, a.tv_usec.int))
elif defined(posix): elif defined(posix):
var ts: Timespec var ts: Timespec
discard clock_gettime(realTimeClockId, ts) discard clock_gettime(CLOCK_REALTIME, ts)
result = initTime(ts.tv_sec.int64, ts.tv_nsec.int) result = initTime(ts.tv_sec.int64, ts.tv_nsec.int)
elif defined(windows): elif defined(windows):
var f: FILETIME var f: FILETIME
@ -2509,11 +2504,11 @@ when not defined(JS):
fib.add(fib[^1] + fib[^2]) fib.add(fib[^1] + fib[^2])
echo "CPU time [s] ", cpuTime() - t0 echo "CPU time [s] ", cpuTime() - t0
echo "Fib is [s] ", fib 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 # 'clocksPerSec' is a compile-time constant, possibly a
# rather awful one, so use clock_gettime instead # rather awful one, so use clock_gettime instead
var ts: Timespec var ts: Timespec
discard clock_gettime(cpuClockId, ts) discard clock_gettime(CLOCK_THREAD_CPUTIME_ID, ts)
result = toFloat(ts.tv_sec.int) + result = toFloat(ts.tv_sec.int) +
toFloat(ts.tv_nsec.int) / 1_000_000_000 toFloat(ts.tv_nsec.int) / 1_000_000_000
else: else:
@ -2531,7 +2526,7 @@ when not defined(JS):
result = toBiggestFloat(a.tv_sec.int64) + toBiggestFloat(a.tv_usec)*0.00_0001 result = toBiggestFloat(a.tv_sec.int64) + toBiggestFloat(a.tv_usec)*0.00_0001
elif defined(posix): elif defined(posix):
var ts: Timespec var ts: Timespec
discard clock_gettime(realTimeClockId, ts) discard clock_gettime(CLOCK_REALTIME, ts)
result = toBiggestFloat(ts.tv_sec.int64) + result = toBiggestFloat(ts.tv_sec.int64) +
toBiggestFloat(ts.tv_nsec.int64) / 1_000_000_000 toBiggestFloat(ts.tv_nsec.int64) / 1_000_000_000
elif defined(windows): elif defined(windows):