Loading topic
perf_counter or timeit. Timing a snippet tells you how long one piece takes. It does not tell you which piece of a larger program to look at. A profiler answers that question.3 min readcProfile. Idioms are small rewrites. They rarely beat a better algorithm, so apply them only to code the profiler has shown to be hot.2 min readcProfile and read tottime and cumulative columns, and that you can use pip and a terminal. Here you learn what a sampling profiler is, when it beats cProfile, and how to use py-spy.3 min readpytest-style tests and have already timed code with timeit and time.perf_counter. A speedup you don't protect can quietly disappear. A later change, a dependency upgrade, or a "harmless" refactor can bring the slow behavior back, and nobody notices until user2 min read