Loading topic
time.perf_counter or timeit. Timing tells you that something is slow. A profiler tells you where the time goes. Here you will run cProfile on a whole program, save its 7 min readcProfile (covered in the previous chapter) and are comfortable with functions, list comprehensions, and generators. It covers how to read the table that profiler produces, so you can tell which function is slow and which one only calls the slow funct6 min readtottime from cumulative, and that you can time a snippet with timeit or time.perf_counter. You should also know how lists, dicts, and sets behave in everyday code. Here you will use a profile to decide whether the code needs a bett5 min readcProfile report and have already used timeit (earlier chapters in this tutorial). It also assumes you know the basics of lists, dicts, sets, and generators. The idioms here are small, local changes. They usually give a constant-factor speedup, not a change in 6 min readfunctools.lru_cache does this w5 min readtracemalloc is in the standard library, so there is nothing to install.6 min readtottime, cumulative, callers), can install packages with pip, and know the basic list, dict, and set trade-offs from earlier chapters. By the end you will be able to profile single functions line by line and tell when the result is trustworthy.6 min readpip. A sampling profiler answers the same question as cProfile, "where does the time go?", but it works differently. It can attach to a program that is already running, and it ad6 min readperf_counter and timeit, read a cProfile report, and install packages with pip. Run pip install numpy before the examples. The profiling chapters showed you how to find a hot loop. Here you will learn one of the most effective fixes for loops that do5 min readtimeit and time.perf_counter from earlier chapters, and you can read a profiler report.6 min readpip and, for the Cython example, a C compiler on your m6 min read