Last active
October 27, 2017 13:12
-
-
Save AntoineToubhans/1a23a578e32e268e7eb52ac63bdeeb2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
from functools import wraps | |
def simple_time_tracker(log_fun): | |
def _simple_time_tracker(fn): | |
@wraps(fn) | |
def wrapped_fn(*args, **kwargs): | |
start_time = time() | |
try: | |
result = fn(*args, **kwargs) | |
finally: | |
elapsed_time = time() - start_time | |
# log the result | |
log_fun({ | |
'function_name': fn.__name__, | |
'total_time': elapsed_time, | |
}) | |
return result | |
return wrapped_fn | |
return _simple_time_tracker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment