Shakshi3104 commited on
Commit
371a1e6
Β·
1 Parent(s): 3e4b2ef

[add] Add timer

Browse files
Files changed (1) hide show
  1. 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