DEV Community

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

Posted 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:

Memray: The endgame Python memory profiler - Talk Python to Me Ep.425 - YouTube

Understanding how your Python application is using memory can be tough. First, Python has it's own layer of reused memory (arenas, pools, and blocks) to help...

favicon youtube.com

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.

Yishai Zinkin - From PyPerf to py-spy - Everything You Need to Know About Python Profilers - YouTube

With the increasing complexity of modern Python applications and the high cost of running them in the cloud––the need for profiling solutions rises. However,...

favicon youtube.com

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)