DEV Community

Cover image for Profiling Python Code for Performance
Rudolf Olah
Rudolf Olah

Posted on • Edited on

Profiling Python Code for Performance

Here are a few tools that are actively maintained that can help you understand and profile the performance of your Python code, from Django apps to Celery workers to desktop GUI apps:

cProfile and tracemalloc are included in the Python Standard Library

The others are libraries that are actively maintained and can be used to diagnose various performance issues.

Memray is great and it works with Python threads and it produces flame graphs for the profiling reports. There's a plugin for pytest that can run Memray so you can profile your test code and the code running within the tests.

Guppy3 is a neat tool for diagnosing memory leak issues.

Fil is a memory profiler that works on Linux and MacOS, that produces flame graphs.

Check out the repo for code examples: https://github.com/rudolfolah/profiling-code/tree/main/python

I've previously written about how to profile performance for React JavaScript frontend builds over here: https://rudolfolah.com/profiling-webpack-node-react/

Cover image by Max Böttinger on Unsplash

Top comments (0)