from functools import wraps import time def func_time(f): @wraps(f) def wrapper(*args, **kwargs): start = time.time() result = f(*args, **kwargs) end = time.time() print(f"\033[1;31;40m{f.__name__} took {(end-start):.3f}s") return result return wrapper @func_time def test_1(): time.sleep(1) @func_time def test_2(): time.sleep(0.5) test_1() test_2() """ test_1 took 1.013s test_2 took 1.519s """