Add debug.timeit() helper
@@ -32,7 +32,9 @@ flexibility to redirect debug output if needed.
import builtins
+import contextlib
import os
+import time
import warnings
from . import markup as _markup
@@ -105,6 +107,15 @@ class flags(metaclass=FlagsMeta):
doc="Disable server query cache. Parse/Execute will always recompile.")
+@contextlib.contextmanager
+def timeit(title='block'):
+ st = time.monotonic()
+ try:
+ yield
+ finally:
+ print(f'{title} took {time.monotonic() - st:.4f}s')
+
+
def header(*args):
print('=' * 80)
print(*args)
