Cython and Numba: Reference

Key Points

Introduction
  • Cython can speed up some computations dramatically

  • Profiling code is a useful way to know whether Cython is helping

Compiling Cython code
  • Cython uses the pyx extension and distutils to compile code to C

  • Another simpler mechanism is provided by pyximport

  • Additional performance gains can be won by using cdef and cpdef objects

Using annotations to improve performance even more
  • Cython provides an annotation system to diagnose the level of interaction with Python

  • Improvements can often be made with this information

  • Additional performance gains can be made with simple compiler instructions

Numba
  • Python can be slow in some conditions

  • Cython an Numba can give substantial performance boosts in some of these

  • Use them judiciously, to make your code faster

Wrap-Up
  • Python can be slow in some conditions

  • Cython an Numba can give substantial performance boosts in some of these

  • There are use-cases in which one of these is better than the other

  • Use them judiciously, to make your code faster

Additional materials: