Book Image

Mastering Python High Performance

Book Image

Mastering Python High Performance

Overview of this book

Table of Contents (15 chapters)

How to choose the right option

Up to this point, we've gone over two different alternatives to radically optimize our code. However, how do we know which one is the right one? Or even better, which one is the best one?

The answer to both those questions is the same: there is no single best or right one. Whether one of the options is better or worse depends entirely on one or more of these aspects:

  • The actual use case you're trying to optimize

  • The familiarity of the developer with either Python or C

  • The importance of readability of your optimized code

  • The amount of time at hand to perform the optimization

When to go with Cython

Here are the situations when you should go with Cython:

  • You're familiar with C code: It's not like you'll be coding in C, but you will be using principles that are common to C, such as static types, and C libraries, such as math.h. So, being familiar with the language and its internals will definitely be helpful.

  • Losing Python's readability is not a problem: The code you...