2026-07-22 –, Room 1.38 (Ground Floor, Turing)
Does your code feel too slow? Do you want to speed it up, but don’t know where to start?
This tutorial introduces attendees to the fundamentals of profiling in Python—why, what, when and how to profile. We start by using Python’s built-in cProfile module to figure out which parts of the code take up most of the runtime, then introduce a third-party module to visualise profiling results and get an overview over the function call hierarchy. In the second half, we use a line-level profiler to precisely pinpoint even a less obvious performance issue, before closing with an outlook on new profiling features coming in Python 3.15 this autumn.
Throughout the tutorial, we include interactive exercises that build on each other. Attendees will get hands-on experience using these tools to systematically investigate performance issues in a Python code base.
This tutorial introduces attendees to the fundamentals of profiling in Python—why, what, when and how to profile.
In the first half, we demonstrate function-level profiling using the Python standard library’s cProfile module and visualise its results with the snakeviz module. In the second half, we demonstrate line-level profiling using line_profiler/kernprof. Finally, we’ll give an outlook on the new profiling module and Tachyon sampling profiler coming in Python 3.15 this autumn.
Throughout the tutorial, we use two types of interactive exercises: Firstly, short toy examples, which are designed to demonstrate each tool in an approachable manner. Secondly, we will investigate a more complex example code using each of these tools in turn, to demonstrate how they build on each other. Attendees will get hands-on experience using these tools to systematically investigate performance issues in a Python code base.
Schedule:
Introduction: Why, What & When to Profile (10 min)
Function-Level Profiling with cProfile (25 min)
Visualising cProfile Results (15 min)
Line-Level Profiling (25 min)
Outlook: Changes in Python 3.15 (10 min)
Conclusion & Next Steps (5 min)
This tutorial is based on a course on Python Profiling and Optimisation developed as part of the Carpentries Incubator program. The profiling section of that course is designed to be delivered independently; it requires only minor adjustments to scope and timings to fit the 90 min tutorial time slot.
As a contributor and co-maintainer, I have previously delivered this course at multiple institutions. I have also presented a brief talk introducing the course at EuroSciPy 2025.
Jost is a Senior Research Software Engineer at King’s College London, where they work on software projects ranging from astrophysics to Trusted Research Environments for analysing medical data. They are a certified Carpentries instructor and regularly develop and deliver training courses, with a focus on Python and high-performance computing for researchers.
Jost received a PhD in astroparticle physics from the University of Sheffield and is a maintainer of several widely used supernova neutrino codes, including SNEWPY and sntools.