What is CPU profiling and how does it help optimization?

Updated May 17, 2026

Short answer

CPU profiling measures how CPU time is spent in code to identify bottlenecks.

Deep explanation

CPU profiling breaks down function execution time, call frequency, and stack traces. It helps identify hot paths where optimization yields maximum benefit. Instead of guessing, developers use profiling data to target inefficient loops, excessive recursion, or heavy computations.

Real-world example

Optimizing image processing pipelines by identifying slow transformation steps.

Common mistakes

  • Optimizing non-critical code paths instead of hot paths.

Follow-up questions

  • What is a flame graph?
  • Difference between CPU and memory profiling?

More Optimisation interview questions

View all →