How to Profile with cProfile
May 30, 2026 | 5 min read
Run cProfile
python -m cProfile -o profile.stats -s cumulative script.pyAnalyse with pstats
python -m pstats profile.stats
> sort cumtime
> stats 20Visualise with SnakeViz
pip install snakeviz
snakeviz profile.statsPick Targets
Select the top 5 functions by cumtime for compilation.