Faster Python calculations with Numba: 2 lines of code, 13× speed-up
Python is a slow language, so computation is best delegated to code written in something faster.
You can do this with existing libraries like NumPy and SciPy, but what happens when you need to implement a new algorithm, and you don’t want to write code in a lower-level language?
For certain types of computation, in particular array-focused code, the Numba library can significantly speed up your code.
Sometimes you’ll need to tweak it a bit, sometimes it’ll just work with no changes.
And when it works, it’s a very transparent speed fix.
In this article we’ll cover:
- Why using NumPy on its own is sometimes not enough.
- The basics of using Numba.
- How Numba works, at a high-level, and the difference that makes to how your code