python装饰器
作者:互联网
import time def cost_time(func): def inner(): t1 = time.perf_counter() func() t2 = time.perf_counter() print(t2 - t1) return inner @cost_time def step_two(): for i in range(10000): print(i) def step_one(): t1 = time.perf_counter() for i in range(10000): print(i) t2 = time.perf_counter() print(t2 - t1) if __name__ == '__main__': step_one() step_two()
装饰器常用用法:
引入日志
函数执行时间统计
执行函数前预处理
执行函数前的清理功能
权限校验
等等
标签:__,perf,python,counter,step,time,print,装饰 来源: https://www.cnblogs.com/jackadam/p/16463699.html