# HG changeset patch # User sam # Date 1723204160 -25200 # Node ID f0020945d016b5d8b08e83e5b7a72b1150b3a181 # Parent b22c3b7bc02674a052c5aeae3ca0852987fd4db8 add: allow do enable/disable time-logs diff -r b22c3b7bc026 -r f0020945d016 semicongine/core/utils.nim --- a/semicongine/core/utils.nim Fri Aug 09 12:46:38 2024 +0700 +++ b/semicongine/core/utils.nim Fri Aug 09 18:49:20 2024 +0700 @@ -34,12 +34,20 @@ func Size*[T: seq](list: T): uint64 = uint64(list.len * sizeof(get(genericParams(typeof(list)), 0))) +const ENABLE_TIMELOG {.booldefine.}: bool = not defined(release) + template TimeAndLog*(body: untyped): untyped = - let t0 = getMonoTime() - body - echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000 + when ENABLE_TIMELOG: + let t0 = getMonoTime() + body + echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000 + else: + body template TimeAndLog*(name: string, body: untyped): untyped = - let t0 = getMonoTime() - body - echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000, "ms" + when ENABLE_TIMELOG: + let t0 = getMonoTime() + body + echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000, "ms" + else: + body