Skip to content

Instantly share code, notes, and snippets.

@AntoineToubhans
Last active October 27, 2017 13:12
Show Gist options
  • Save AntoineToubhans/1a23a578e32e268e7eb52ac63bdeeb2a to your computer and use it in GitHub Desktop.
Save AntoineToubhans/1a23a578e32e268e7eb52ac63bdeeb2a to your computer and use it in GitHub Desktop.
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