-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
25 lines (21 loc) · 767 Bytes
/
Copy pathutils.py
File metadata and controls
25 lines (21 loc) · 767 Bytes
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
import functools, timeit
def timer(func):
"""Prints the runtime of the decorated function."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = timeit.default_timer()
value = func(*args, **kwargs)
end_time = timeit.default_timer()
elapsed_time = end_time - start_time
msg = f'Took {round(elapsed_time, 2)} seconds.'
script_obj = args[0]
try:
if script_obj.generate_excel:
msg += ' (Including the time it took to generate the Excel file.)'
else:
msg += ' (NOT including the time it took to generate the Excel file.)'
except AttributeError:
pass
print(msg)
return value
return wrapper