Created
November 5, 2018 08:43
-
-
Save RRRoger/cbaa87a851ea234921c2c05d0cc470b3 to your computer and use it in GitHub Desktop.
计算函数耗时多久
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
def time_cost(f): | |
""" | |
:param f: function | |
:return: 计算函数耗时多久 | |
""" | |
def _wrapper(*args, **kwargs): | |
now = time.time() | |
res = f(*args, **kwargs) | |
log_txt = u'函数 %s 耗时 %.2fs!' % (f.__name__, time.time() - now) | |
_logger.info(log_txt) | |
print log_txt | |
return res | |
return _wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment