Skip to content

Instantly share code, notes, and snippets.

@lawlite19
Created November 28, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlite19/caeecc99435f2d157aa27a810e3d3daa to your computer and use it in GitHub Desktop.
Save lawlite19/caeecc99435f2d157aa27a810e3d3daa to your computer and use it in GitHub Desktop.
函数运行时间统计
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