Book Image

Mastering Python High Performance

Book Image

Mastering Python High Performance

Overview of this book

Table of Contents (15 chapters)

Chapter 4. Optimize Everything

The path to mastering performance in Python has just started. Profiling only takes us half way there. Measuring how our program is using the resources at its disposal only tells us where the problem is, not how to fix it. In the previous chapters, we saw some practical examples when going over the profilers. We did some optimization, but we never really explained a lot about it.

In this chapter, we will cover the process of optimization, and to do that, we need to start with the basics. We'll keep it inside the language for now: no external tools, just Python and the right way to use it.

We will cover the following topics in this chapter:

  • Memoization / lookup tables

  • Usage of default arguments

  • List comprehension

  • Generators

  • ctypes

  • String concatenation

  • Other tips and tricks of Python