Python Performance Optimization – 3 Ways to make Python go Vroooom

Performance Optimized Python

I love making existing code run faster. There’s something incredibly satisfying about taking code and optimizing it to get the same results, but a lot faster. When I was getting my Masters degree I took a deep dive into processor-level optimization and what I learned blew my mind. Now, fast-forward over a decade later and my mind is still being blown by some of the amazing ways you can improve the performance of code today.

Python is one of my favorite programming languages on the planet and awesome companies like Buzzfeed and Fashion Metric (shameless plug) use it to drive innovation. Of course you can innovate faster if your code runs faster so I thought I’d share three ways to really get your code running like a finely tuned Ferrari.

Cython

1. Cython – without a doubt the most well-known way to improve the performance of Python code is with Cython. Like the name says, Cython allows you the harness the power of C without having to make massive changes to your code. In my opinion you get the best of both worlds, the power of Python but the speed and performance benefits of C.

Parakeet Python Logo

2. Parakeet – okay, I agree, when I think of a parakeet I don’t think of a speedy bird, but don’t let the name fool you. Parakeet is a runtime compiler for scientific computing in Python and it can make operationally expensive array operations lightning-fast. The best thing about Parakeet is that it requires almost no code changes and the performance increases can be huge.

CUDA Python

3. CUDA/NumbaPro – I decided to save the best for last. If you really want to make your code blazing fast forget those silly CPU’s and harness the power of NVidia GPUs. While you can’t do this on most hosting providers it is possible to do it fairly easily on Amazon AWS using a GPU instance. I’ll probably write a deeper tutorial on how to get this going but for now you can check-out this page for information about GPU accelerated computing with Python.


Photo Credit: mroach via Compfight cc

Morgan Linton

Morgan Linton