Python装饰器 计时器记录方法执行性能
import time
def timeit(func):
def wrapper():
start = time.clock()
func() end =time.clock()
print 'used:', end - start
return wrapper
@timeit
def foo():
print 'in foo()' foo()
Never give up !
import time
def timeit(func):
def wrapper():
start = time.clock()
func() end =time.clock()
print 'used:', end - start
return wrapper
@timeit
def foo():
print 'in foo()' foo()