-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
31 lines (24 loc) · 787 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
sys.path.append("")
from functools import wraps
import time
def convert_ms_to_hms(ms):
seconds = ms / 1000
hours = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
seconds = round(seconds, 2)
return f"{int(hours)}:{int(minutes):02d}:{seconds:05.2f}"
def timeit(func):
@wraps(func)
def timeit_wrapper(*args, **kwargs):
start_time = time.perf_counter()
result = func(*args, **kwargs)
end_time = time.perf_counter()
total_time = end_time - start_time
# first item in the args, ie `args[0]` is `self`
time_delta = convert_ms_to_hms(total_time*1000)
print(f'{func.__name__.title()} Took {time_delta}')
return result
return timeit_wrapper