Decorator 2_2024_10_07

Run Settings
LanguagePython
Language Version
Run Command
def timed(fn): from time import perf_counter from functools import wraps @wraps(fn) def inner(*args, **kwargs): start = perf_counter() result = fn(*args, **kwargs) end = perf_counter() elapsed = end - start args_str = ', '.join([str(a) for a in args] + [f"{k}={v}" for k, v in kwargs.items()]) print(f'{fn.__name__}({args_str}) took {elapsed:.6f}s to run.') return result return inner def calc_recursive_fib(n): if n<= 2: return 1 else: return calc_recursive_fib(n-1) + calc_recursive_fib(n-2) calc_recursive_fib(3) @timed def fib_recursed(n): return calc_recursive_fib(n) fib_recursed(33)
Editor Settings
Theme
Key bindings
Full width
Lines