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
Test sequentially first
Use logging (not print)
Reduce parallelism (2 workers)
Validate intermediate results
Isolate before parallelizing
Tip
Integration test: Verify expected speedup (4 processes ≈ 4x faster)