Python·100 questionsHow to profile Python code?SaveUpdated: 2026-08-31Answer•cProfile for general profiling.•timeit for micro-benchmarks.•line_profiler for line-by-line analysis.•py-spy for production without injection.•Measure first, then optimize.Ask AI to clarifyWas this answer helpful?HelpfulNot helpfulSuggest an improvement