添加耗时统计装饰器工具
This commit is contained in:
@@ -1,4 +1,25 @@
|
||||
import os
|
||||
import time
|
||||
from functools import wraps
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def timeit(func):
|
||||
"""
|
||||
装饰器:计算函数执行时间
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
start_time = time.time()
|
||||
result = func(*args, **kwargs)
|
||||
end_time = time.time()
|
||||
logger.info(
|
||||
f"Function {func.__name__} executed in {end_time - start_time:.4f} seconds"
|
||||
)
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def ensure_directory_exists(target_path: str, is_file: bool = False):
|
||||
|
||||
Reference in New Issue
Block a user