6

Profile Python Code with line_profiler

 3 years ago
source link: https://jdhao.github.io/2020/11/06/profile_python_line_profiler/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Profile Python Code with line_profiler

2020-11-06 116 words 1 min read 80 times read

To profile Python code line by line. We can use line_profiler1.

Install

Linux:

Just use pip:

pip install line_profiler

Windows

It is easier to use conda since it does not require building the package:

# if you use pip on Windows, you must have Visual Studio to build the package.
conda install line_profiler

How to profile?

Annotate the function we want to profile with @profile annotation. On the command line, run:

kernprof -v -l test_script.py

The command line options to test_script.py can be followed after it. Just like you call python test_script.py.


  1. This is a fork of original line_profiler repo. The original repo is not maintained. ↩︎

Author jdhao

LastMod 2020-11-06

License CC BY-NC-ND 4.0

Reward
Prev Next
Powered by Hugo | Theme - Even
site pv: 1538186 | site uv: 1145124
© 2017 - 2020jdhao

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK