25 July 2011 - 9:42High Performance Python tutorial v0.2 (from EuroPython 2011)
My updated High Performance Python tutorial is now available as a 55 page PDF. The goal is to take you on several journeys which show you different ways of making Python code run much faster (up to 75* on the CPU, faster with a GPU).
UPDATE As of October 2014 I’ll be teaching High Performance Python and Data Science in London, sign-up here to join our announce list (no spam, just occasional notes about our upcoming courses).
UPDATE (2014) I’ve written the High Performance Python book with O’Reilly, it is publishing this year.
UPDATE 1 this talk is superseded by my High Performance Python 1 tutorial from PyCon 2012.
UPDATE 2 I’m thinking of writing an updated guide, if you’re interested in hearing about it please join the High Performance Python Mailing List (I’ve only got a list right now). I’ll make an announce once I know more.
UPDATE 3 (Sept 2012) I was missing the EuroPython video, I’ve embedded it down below.
This is an update to the 49 page v0.1 I published three weeks ago after running the tutorial at EuroPython 2011 in Florence.
- Python profiling (cProfile, RunSnake, line_profiler) – find bottlenecks
- PyPy – Python’s new Just In Time compiler, a note on the new numpy module
- Cython – annotate your code and compile to C
- numpy integration with Cython – fast numerical Python library wrapped by Cython
- ShedSkin – automatic code annotation and conversion to C
- numpy vectors – fast vector operations using numpy arrays
- NumExpr on numpy vectors – automatic numpy compilation to multiple CPUs and vector units
- multiprocessing – built-in module to use multiple CPUs
- ParallelPython – run tasks on multiple computers
- pyCUDA – run tasks on your Graphics Processing Unit
- Other algorithmic choices and options you have
The improvement over the last version (v0.1) is that I’ve filled in all the sections now including pyCUDA (there are still a few IAN_TODOs marked, I hope to finish these in a future v0.3). I’ve also added a short section on Algorithmic Choices, link to the new Cython prange operator and show the new numpy module in PyPy.
Here’s the video from EuroPython (via pyvideo.org):
The source code is on my github page. The original slides are on slideshare too. If you’re after a challenge then at the end of the report I suggest some ported versions of the code that I’d like to see.
The report is licensed Creative Commons by Attribution (please link back here) – I’ll also happily accept a beer if you meet me in person! If you’re curious about this sort of work then note that I offer A.I. and high performance computing consulting and training via my Mor Consulting.
Update – ShedSkin 0.9 adds faster complex number support. I haven’t added it to the report yet, evidence in the ShedSkin Group suggests it gets closer to the non-complex-number version (i.e. you don’t have to do more work but you get a nice speed boost whilst still using complex numbers).
Update (Nov 2011) – Antonio and Armin posted a note which explains some of the slowness in PyPy and show how it is competitive, under the right conditions. Armin also contributed a C version which shows PyPy to run as fast as C (for their chosen configuration).
Ian applies Data Science as an AI/Data Scientist for companies in ModelInsight, sign-up for Data Science tutorials in London. Historically Ian ran Mor Consulting. He also founded the image and text annotation API Annotate.io, co-authored SocialTies, programs Python, authored The Screencasting Handbook, lives in London and is a consumer of fine coffees.