Step 3: the timing wrapper
English · Dansk · Bahasa Malaysia
The wrapper reads the clock before and after the call and prints the difference:

Run it with python -m speed_calc.lecture_steps 3.
What we gained
- A decorator can run code before and after the function without changing the function.
- The wrapper returns the function's result, so the decorated function still works as before.
make_speed_calc_decorator(clock, output) takes the clock and the output as parameters. The tests give it a fake clock, so they check exact values and never wait for real time.
- The text format lives in
constants.py, the one place for constants.