Q53: How do you profile Python code performance using cProfile and line_profiler?

  • cProfile: Built-in deterministic profiler tracking function call frequency and execution duration.
  • line_profiler: Third-party tool providing line-by-line execution duration breakdowns across individual code statements.
Key Takeaways
  • cProfile: Tracks function-level invocation counts and execution durations.
  • line_profiler: Identifies bottleneck statements line-by-line.
Knowledge Check

Which built-in module measures cumulative execution times for Python function calls?