自定义计算函数运行耗时的函数
import time import functools def running_time(func): @functools.wraps(func) def wrapper(*args,**kwargs): start=time.time() result=func(*args,**kwargs) end=time.time() print('Calling %s() consumes %.3f seconds.'%(func.__name__,end-start)) return result return wrapper @running_time def test(): print('testing...') for i in range(1000*1000*20): isinstance('123',str) if __name__=='__main__': test()