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 ...

Get Mastering Python High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.