Discuss / Python / 小白作业

小白作业

Topic source

import time,functools

def metric(fn): @functools.wraps(fn) def wrapper(args, **kw): d1 =int(round(time.time()1000)) #毫秒级时间 func = fn(args, **kw) d2 =int(round(time.time()1000)) #毫秒级时间 print(f'{fn.name} executed in {d2-d1} ms') return func return wrapper

@metric

def fast(x, y): time.sleep(0.0012) return x + y;

@metric

def slow(x, y, z): time.sleep(0.1234) return x y z;

print(fast(11, 22)) print(slow(11, 22, 33))


  • 1

Reply