Before rewriting slow Python or moving it into Cython, it helps to find out what is actually slow.

This Compute Ontario Colloquium was an introduction to Scalene. Scalene separates time spent in Python from time spent in native libraries, and it can also profile memory and GPU use. I ran it on the Alliance systems from a Jupyter notebook, then compared native Python, vectorized code, Cython, and just-in-time compilation.

Abstract

Python is a language developers choose to write in for convenience rather than speed. However, speed can be recovered by offloading calculations to libraries which leverage lower-level languages like NumPy, Cython, and more. Scalene is a high-performance CPU, GPU, and memory profiler which can illustrate where code should be passing calculations to other libraries for significant increases in speed. Scalene also includes support for Jupyter Notebooks, OpenAI suggestions for vectorizing code, as well as a significantly lower overhead and higher accuracy than other profilers. This talk will introduce the concepts required for understanding why external libraries are faster than native Python, interactions with approaches such as Cython and just-in-time compilers, as well as a live demonstration of Scalene on the Alliance systems inside of a Jupyter Notebook. Familiarity with Python, virtual environments, and Jupyter notebooks will be assumed.

The slides, notebooks, and examples are available on GitHub.