Created
August 10, 2021 16:16
-
-
Save neontty/2ac36728a7e402805f08f6d7d301fa03 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
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