Interview prompt
Explain profile before rewriting the slow path to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.
A strong answer
Profiling attributes resource use to parts of a running program; benchmarking compares defined workloads under controlled conditions. A useful optimization starts with a hypothesis about the bottleneck and gathers evidence at the level where the cost occurs.
If a CPU profile shows most samples inside JSON parsing, tuning database indexes will not fix the measured CPU bottleneck. A benchmark should use representative data, warm-up behavior, stable machine conditions, and enough repetitions to show variation rather than one favorable run.
A complete answer also calls out the assumptions that control correctness. Instrumentation adds overhead and can distort timing, so use the least intrusive tool that answers the question. Microbenchmarks isolate operations but may fail to predict full-system behavior. Preserve correctness checks and compare end-to-end latency after any local speedup.
Close by describing one representative test or measurement. A new implementation is twice as fast in a microbenchmark but the endpoint latency is unchanged. Name three possible reasons and the next measurement you would collect.
Follow-up questions
Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.