2024-03-20 11:44:15 +08:00
|
|
|
|
import logging
|
2024-07-19 15:10:28 +08:00
|
|
|
|
import time
|
2024-03-20 11:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def RunTime(func):
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
|
res = func(*args, **kwargs)
|
|
|
|
|
|
t2 = time.time()
|
2025-01-10 15:02:28 +08:00
|
|
|
|
if t2 - t1 > 0.05:
|
|
|
|
|
|
logging.info(f"function:【{func.__name__}】,runtime:【{str(t2 - t1)}】s")
|
|
|
|
|
|
# logging.info(f"function:【{func.__name__}】,runtime:【{str(t2 - t1)}】s")
|
2024-03-20 11:44:15 +08:00
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|
2024-07-19 15:10:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ClassCallRunTime(func):
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
result = func(*args, **kwargs)
|
|
|
|
|
|
end_time = time.time()
|
|
|
|
|
|
execution_time = end_time - start_time
|
|
|
|
|
|
class_name = args[0].__class__.__name__ # 获取类名
|
|
|
|
|
|
print(f"class name: {class_name} , run time is : {execution_time} s")
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
return wrapper
|