High performance Python: Reference

Key Points

Introduction
Introduction to Cython
  • Cython can speed up some computations dramatically

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 and Numba can give substantial performance boosts in some of these

  • Use them judiciously, to make your code faster

Dask
  • If computations lend themselves to parallelization, they can be sped up substantially

  • Dask arrays can speed up things even more, for array data

  • Dask provides a whole universe of tools for parallelization

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: