In this chapter, we introduced the basic principles of optimization and we applied those principles to our test application. The most important thing is identifying the bottlenecks in the application before editing the code. We saw how to write and time a benchmark using the
time Unix command and the Python
timeit module. We learned how to profile our application using
memory_profiler, and how to analyze and navigate graphically the profiling data with KCachegrind. We surveyed some of the strategies to optimize pure Python code by leveraging the tools available in the standard library.
In the next chapter, we will see how to use
numpy to dramatically speedup computations in an easy and convenient way.