Search⌘ K
AI Features

Use a line_profiler

Explore how to use the line_profiler tool and the kernprof script to profile the execution time of individual Python code lines. Learn to decorate functions for profiling, handle output results, and use different methods to analyze performance, including IPython magic commands for interactive profiling.

There’s a neat 3rd party project called line_profiler that is designed to profile the time each individual line takes to execute. It also includes a script called kernprof for profiling Python applications and scripts using line_profiler. Just use pip to install the package.

Getting started with line_profiler

Here’s how:

pip3 install line_profiler

To actually use the line_profiler ...