Skip to content

Instantly share code, notes, and snippets.

@neontty
Created August 10, 2021 16:16
Show Gist options
  • Save neontty/2ac36728a7e402805f08f6d7d301fa03 to your computer and use it in GitHub Desktop.
Save neontty/2ac36728a7e402805f08f6d7d301fa03 to your computer and use it in GitHub Desktop.
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
print '%r %2.2f ms' % \
(method.__name__, (te - ts) * 1000)
return result
return timed
#usage:
@timeit
def get_all_employee_details(**kwargs):
print 'employee details'
# source: https://medium.com/pythonhive/python-decorator-to-measure-the-execution-time-of-methods-fa04cb6bb36d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment