装饰器,记录方法执行时间
python
# -*- coding: utf-8 -*-
import time
def fun_timer(*args):
print('装饰器参数 : ',args)
def wrapper(fun):
def _wrapper(*funargs):
print('方法参数 : ', funargs)
if args[0] == 0:
print('开始执行 : ', time.time())
result = fun(*funargs)
if args[1] == 0:
print('结束时间 : ', time.time())
return result
return _wrapper
return wrapper
@fun_timer(0,0)
def add(a,b):
print('all',a,b)
return a+b
if __name__ == '__main__':
print(add(1,2))
# -*- coding: utf-8 -*-
import time
def fun_timer(*args):
print('装饰器参数 : ',args)
def wrapper(fun):
def _wrapper(*funargs):
print('方法参数 : ', funargs)
if args[0] == 0:
print('开始执行 : ', time.time())
result = fun(*funargs)
if args[1] == 0:
print('结束时间 : ', time.time())
return result
return _wrapper
return wrapper
@fun_timer(0,0)
def add(a,b):
print('all',a,b)
return a+b
if __name__ == '__main__':
print(add(1,2))