NDOJ/dmoj/decorators.py

15 lines
352 B
Python
Raw Permalink Normal View History

2022-04-16 21:05:55 +00:00
import time
2022-05-14 17:57:27 +00:00
2022-04-16 21:05:55 +00:00
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
2022-05-14 17:57:27 +00:00
if "log_time" in kw:
name = kw.get("log_name", method.__name__.upper())
kw["log_time"][name] = int((te - ts) * 1000)
2022-04-16 21:05:55 +00:00
return result
2022-05-14 17:57:27 +00:00
return timed