Browse Source

Added exec time decor

thehamkercat 5 năm trước cách đây
mục cha
commit
57b5dde08c
1 tập tin đã thay đổi với 19 bổ sung và 0 xóa
  1. 19 0
      wbb/core/decorators/misc.py

+ 19 - 0
wbb/core/decorators/misc.py

@@ -0,0 +1,19 @@
+from functools import wraps
+from time import time
+
+
+def exec_time(func):
+    @wraps(func)
+    async def _time_it(*args, **kwargs):
+        t1 = time()
+        try:
+            return await func(*args, **kwargs)
+        finally:
+            t2 = time()
+            total = t2 - t1
+            total = round(total, 3)
+            print(
+                f"{func.__name__} Took: {total} Seconds"
+            )
+
+    return _time_it