summaryrefslogtreecommitdiffstats
path: root/etc/testing/log_time.py
diff options
context:
space:
mode:
Diffstat (limited to 'etc/testing/log_time.py')
-rw-r--r--etc/testing/log_time.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/etc/testing/log_time.py b/etc/testing/log_time.py
new file mode 100644
index 00000000..376ab86d
--- /dev/null
+++ b/etc/testing/log_time.py
@@ -0,0 +1,25 @@
+from time import time
+
+
+async def log_time_async(method: callable, **kwargs):
+ start = time()
+ result = await method(**kwargs)
+ secs = f"{round(time() - start, 2)} secs"
+ if result:
+ return " ".join([result, secs])
+ return secs
+
+
+def log_time_yield(method: callable, **kwargs):
+ start = time()
+ result = yield from method(**kwargs)
+ yield f" {round(time() - start, 2)} secs"
+
+
+def log_time(method: callable, **kwargs):
+ start = time()
+ result = method(**kwargs)
+ secs = f"{round(time() - start, 2)} secs"
+ if result:
+ return " ".join([result, secs])
+ return secs \ No newline at end of file