python装饰器之函数执行时间
作者:YXN-python 阅读量:83 发布日期:2023-02-28
import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"函数{func.__name__} 执行耗时 {end_time - start_time:.5f} 秒")
return result
return wrapper
@timer
def my_data_processing_function():
# 业务逻辑代码
time.sleep(2)
YXN-python
2023-02-28