parms:dict
包含将被传递给函数的参数的字典
例如'parms'是'{'parms',1},函数会调用'func(parm1=1)'
str包含执行'func'和参数'parms'所花费的时间
格式
it took days,hours,mins,andsecs to execute the function
import datatime as dt
def time_this(func,parms):
parms:dict
包含将被传递给函数的参数的字典
例如'parms'是'{'parms',1},函数会调用'func(parm1=1)'
str包含执行'func'和参数'parms'所花费的时间
格式
it took days,hours,mins,andsecs to execute the function
import datatime as dt
def time_this(func,parms):
from datetime import datetime
import time
def func_test(param1=None):
time.sleep(3.2)
print(param1)
def time_it(func, parms):
start_time = datetime.now()
func(**parms)
end_time = datetime.now()
td = end_time - start_time
days, hours, minutes, seconds = td.days, td.seconds // 3600, td.seconds % 3600 // 60, td.seconds % (3600 * 60)
return f"执行该函数花费{days}天{hours}小时{minutes}分{seconds}秒"
res = time_it(func_test, {'param1': 3})
print(res)