import time,functools
def metric(fn): @functools.wraps(fn) def wrapper(a,**b): now=time.time() n=fn(a,**b) now=time.time()-now print('%s executed in %s ms'%(fn.name,now)) return n return wrapper @metric
def fast(x,y): print('x+y=%d' % (x+y)) fast(2,4)
Sign in to make a reply
Carlos_EN
-- coding: utf-8 --
import time,functools
def metric(fn): @functools.wraps(fn) def wrapper(a,**b): now=time.time() n=fn(a,**b) now=time.time()-now print('%s executed in %s ms'%(fn.name,now)) return n return wrapper @metric
def fast(x,y): print('x+y=%d' % (x+y)) fast(2,4)