Created
November 28, 2018 03:20
-
-
Save lawlite19/caeecc99435f2d157aa27a810e3d3daa 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
import time | |
def timeit(func): | |
""" | |
装饰器,计算函数执行时间 | |
""" | |
def wrapper(*args, **kwargs): | |
time_start = time.time() | |
result = func(*args, **kwargs) | |
time_end = time.time() | |
exec_time = time_end - time_start | |
print("{function} exec time: {time}s".format(function=func.__name__,time=exec_time)) | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment