Profiling and Debugging

Profiling and Debugging#

Important

Profile before optimizing — Intuition about performance is often wrong

📊 Profiling Tools

Quick timing: time.perf_counter()
Full analysis: cProfile
Line-by-line: line_profiler
Memory: memray

Find bottlenecks first

🐛 Debugging Strategy
  1. Test sequentially first

  2. Use logging (not print)

  3. Reduce parallelism (2 workers)

  4. Validate intermediate results

Isolate before parallelizing

Tip

Integration test: Verify expected speedup (4 processes ≈ 4x faster)