Skip to content

Commit 1c88f0e

Browse files
committed
Wrote a function timing decorator
1 parent 0d25de5 commit 1c88f0e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packet/debug_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Functions for use when debugging
3+
"""
4+
5+
from functools import wraps
6+
from datetime import datetime
7+
8+
def log_time(func):
9+
"""
10+
Decorator for logging the execution time of a function
11+
"""
12+
@wraps(func)
13+
def wrapped_function(*args, **kwargs):
14+
start = datetime.now()
15+
16+
result = func(*args, **kwargs)
17+
18+
seconds = (datetime.now() - start).total_seconds()
19+
print("{}.{}() returned after {} seconds".format(func.__module__, func.__name__, seconds))
20+
21+
return result
22+
23+
return wrapped_function

0 commit comments

Comments
 (0)