Last active
October 11, 2018 03:34
-
-
Save lawvs/814b1c6cf076d3ac6bd41210745bac37 to your computer and use it in GitHub Desktop.
Function timer
This file contains 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 importlib | |
# @timer | |
def timer(fn): | |
time = importlib.import_module('time') # dynamic import | |
def wrapper(*args, **kw): | |
print('[{}]: Task starting...'.format(fn.__name__)) | |
START = time.time() | |
res = fn(*args, **kw) | |
END = time.time() | |
print('[{}]: Task total used {}s'.format( | |
fn.__name__, round(END - START, 3))) | |
return res | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment