from contextlib import wraps as _wraps from time import time as _time def runtime(func): @_wraps(func) def wrapper(*args, **kwargs): before = _time() (ret:=func(*args, **kwargs)) print(f'function "{func.__name__}" took {_time() - before} seconds.') return ret return wrapper