Six pages and a sidebar, each lecture step with its screenshot and what it taught; review record RC-008. Refs #14 Refs #15 Refs #16 Refs #17 Refs #18
1.2 KiB
1.2 KiB
Speed Calc Decorator
English · Dansk · Bahasa Malaysia
A Python decorator that measures how many seconds a function takes to run. It is the solution to a lecture exercise of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp. This wiki explains what each lecture step taught. The README is the short version.
The expected output of the finished program has this shape (the numbers differ on every machine):
1695050908.1985211
fast_function run speed: 0.33974480628967285s
slow_function run speed: 2.9590742588043213s
| Page | Read when you want to |
|---|---|
| Setup | Create a local .venv, run the program and run the tests |
| Step 1: the current time | Learn what time.time() returns and how to measure a duration |
| Step 2: the decorator skeleton | Learn what a decorator is and why functools.wraps matters |
| Step 3: the timing wrapper | See how the wrapper times the call and how tests avoid real time |
| Step 4: fast against slow | Put it together and read the result |