-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
44 lines (31 loc) · 1.02 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
def prvalue(print_time: bool = False, print_result=False):
def decortor(func):
def wrapper(*args, **kwargs):
time_s = time.time()
result = func(*args, **kwargs)
time_e = time.time()
if print_result:
print(f"{result=}")
if print_time:
print(
f"Function {func.__name__} "
f"took {time_e - time_s:.10f} seconds to execute\n"
)
return result
return wrapper
return decortor
class CommonUtils:
@staticmethod
def logging_time(original_fn):
def wrapper_fn(*args, **kwargs):
start_time = time.time()
result = original_fn(*args, **kwargs)
end_time = time.time()
print(
f'Method: {original_fn.__name__}'
f'\nResult: {result}'
f'\nTime: {end_time - start_time}'
)
return result
return wrapper_fn