# 利用装饰器获取函数运行时间!
import time
import logging
from functools import wraps
log = logging.getLogger(__name__)
def get_exc_time(func):
@wraps(func)
def _wrapper(*args, **kwargs):
start_time = time.time()
func()
end_time = time.time()
exc_time = end_time - start_time
print("Function [%s] execution time =%s secconds" % (func.__name__, exc_time))
return func
return _wrapper
@get_exc_time
def foo():
time.sleep(1)
foo()
利用python装饰器获取函数运行时间
最新推荐文章于 2024-06-11 06:00:00 发布