Cython can yield massive performance improvements over pure Python--speedups of 3000X are easily attainable for certain patterns. With this book, Kurt Smith shows you how to use Cython to easily wrap C and C++ libraries in Python, handling all the details of memory management for you. By removing the barrier between Python and C, Cython harnesses the best of both languages while remaining familiar and comfortable to Python users.Cython has proven its usefulness in many foundational Pandas, SymPy, Sage, and dozens of others, both open and closed source. You'll learn how Cython is an essential part of any performance-oriented Python programmer's arsenal.
My browser just ate the entire original version of this review because I'm a klutz. But here's the short version.
- Python is slow. C is fast. - Programming in Python is easy. Programming in C is hard. - Cython bridges the gap. Write Python, convert it to C incrementally. - This book does a great job of walking you through the process and teaching you how to get the most out of one of the best things to happen to Python since Guido van Rossum himself. - It's aimed mainly at number-crunchers -- lots of focus on integration with Numpy -- but the motivated programmer can easily see how to apply it to many other fields. (In my case, I wrote a video game and got massive speedups by moving performance-crucial code to C with Cython, mainly the collision detection algorithms.) - Not a long book, but that adds to its accessibility. - Anyone remotely interested in enhancing Python performance where it's warranted* deserves to pick this up.
* Python's big appeal is that it swaps programmer convenience for raw performance. A script thrown together in ten minutes that takes two minutes to run will always beat a program that takes two days to put together but executes in a tenth of a second. But with Cython, we're reaching a point where we don't have to compromise.
Kurt Smith's Cython is very clear. With only a few days of reading and coding, I was able to speed up my pure-Python simulation from 6 s per iteration to just 30 ms! If you're simulating physics in Python on a workstation, I highly recommend this book.
Really nice if you want to get familiar with lower-level implementation with Python, especially for scientific computing. I enjoyed the sections on typed memoryviews and OpenMP (prange) + concrete examples with speedups measure.