Spaces:
Sleeping
Sleeping
Shakshi3104
commited on
Commit
Β·
371a1e6
1
Parent(s):
3e4b2ef
[add] Add timer
Browse files- model/utils/timer.py +20 -0
model/utils/timer.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import wraps
|
2 |
+
import time
|
3 |
+
|
4 |
+
from loguru import logger
|
5 |
+
|
6 |
+
|
7 |
+
# https://qiita.com/hisatoshi/items/7354c76a4412dffc4fd7
|
8 |
+
def stop_watch(func):
|
9 |
+
"""
|
10 |
+
ε¦ηγ«γγγζιθ¨ζΈ¬γγγγγ³γ¬γΌγΏ
|
11 |
+
"""
|
12 |
+
@wraps(func)
|
13 |
+
def wrapper(*args, **kargs):
|
14 |
+
logger.debug(f"π¦ [@stop_watch] measure time to run `{func.__name__}`.")
|
15 |
+
start = time.time()
|
16 |
+
result = func(*args, **kargs)
|
17 |
+
elapsed_time = time.time() - start
|
18 |
+
logger.debug(f"π¦ [@stop_watch] take {elapsed_time:.3f} sec to run `{func.__name__}`.")
|
19 |
+
return result
|
20 |
+
return wrapper
|