Photo by Bozhin Karaivanov on Unsplash

Hands-on Tutorial

Python Runtime Profiling using SnakeViz — How to Inspect the Codes Performances

Determine which part of your Python codes takes more time to run

9 min readJul 3, 2021


After reading and doing step-by-step in this tutorial, you will get some new knowledge and experiences in Python script profiling, how to create profiling on your own script or function, and determine which part of the function takes more time to run.

Introduction to Python script profiling

When working in production, other than bugs occurring in Python script, the run time execution will be one consideration. It is a performance issue when our data volume becomes bigger and bigger. The production script must be restructured and optimized to improve performance.

What if the scripts are too complex to check line by line? Are there any tools to summarize the script performance rather than wasting our time checking line by line and file by file? Yups, we need Python script profiling and Python has several options of modules to do it.

In this tutorial, we will use cProfile to create profiling.

Introduction to cProfile



Audhi Aprilliant

Data Scientist. Tech Writer. Statistics, Data Analytics, and Computer Science Enthusiast. Portfolio & social media links at