changeset 1312:f0020945d016

add: allow do enable/disable time-logs
author sam <sam@basx.dev>
date Fri, 09 Aug 2024 18:49:20 +0700
parents b22c3b7bc026
children f7994a03b802
files semicongine/core/utils.nim
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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