- Python is a dynamic language with no built-in static typing.
- Pure Python is generally slow for numeric computation.
In this notebook I go through a series of techniques that are available for making numerical code fast within Python. This is heavily based on the examples found in Performance Python and the Speeding up Python blog post by Travis Oliphant.
Profiling!
Sometimes you'll be surprised where your code is spending time.
Two places to start:
- Standard library profile module: by function
- Line profiler: line-by-line
- Parallelization (e.g. multiprocessing, IPython parallel processing, MPI, etc etc.
- PyPy: alternate implementation of Python that uses JIT compilation to achieve high performance (geometric mean speedup of about 6 over CPython). They are obsessed with speed.
Solve the 2D Laplace equation with a specified boundary condition using an iterative finite difference scheme (four point averaging, Gauss-Seidel or Gauss-Jordan).