2024-01-09 19:46:17 +08:00

41 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 函数的装饰器,用于获取计算时间(秒)
def timer_decorator(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"Running time of {func.__name__}: {end - start} seconds")
return result
return wrapper
# 函数的装饰器,用于获取计算时间(分)
def timer_decorator_minutes(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"Running time of {func.__name__}: {(end - start)/60} minutes")
return result
return wrapper
# 函数的装饰器,用于获取计算时间(时)
def timer_decorator_hours(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"Running time of {func.__name__}: {(end - start)/3600} hours")
return result
return wrapper
# 函数的装饰器用于GUAN软件包的统计
def statistics_decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
import guan
guan.statistics_of_guan_package(func.__name__)
return result
return wrapper