vprof --I tried using the profiler for Python

Since vprof has been posted on twitter, I will make a note of how to use it. The vprof README.md is better written, so it may be faster to read it.

What is vprof

vprof is a Python package that provides interactive visualization of profile information.

Installation

https://pypi.python.org/pypi/vprof

The current latest version on the pypi is 0.3. (As of May 21, 2016) For the time being, install it with pip.

$ pip install vprof

If you look at README.md

## Prerequisites
The required dependencies to build ```vprof``` from source code:
 * Python 2.7, Python 3.4 or Python 3.5
 * ```pip```
 * ```npm``` >= 3.3.12

So it seems that node is also needed.

Benchmark script

This time I tried to benchmark this script.

#! /usr/bin/env python
import sys
import time


def calc():
    num = 0
    for ii in range(100):
        ii += 1
        time.sleep(0.01)
    return num


def alloc_large_memory():
    txt = 'a' * 1024 * 1024 * 100  # 100MB
    return txt


def main():
    calc()
    alloc_large_memory()

if __name__ == '__main__':
    sys.exit(main())

Try to run

$ vsof -cmh "./benchmark.py"

Specify the display target with the -n option.

option Display target Details
c framechart Frame chart
m memory stats memory usage
h code heatmap Row-by-line heatmap

framechart

The execution time and the number of calls are visualized.

スクリーンショット 2016-05-21 15.32.02.png

To be honest, the list displayed by cprofile may be easier to process and see. .. ..

memory stats

Memory usage is visualized.

スクリーンショット 2016-05-21 15.32.11.png

It is quite good because you can see the file name and the number of lines when measuring the memory usage.

code heatmap

It is a heat map.

スクリーンショット 2016-05-21 15.32.28.png

It seems that the places with many executions are displayed in dark colors. This looks good. I didn't know how to display the file that I was importing ...

Recommended Posts

vprof --I tried using the profiler for Python
Miscellaneous notes that I tried using python for the matter
I tried using the python module Kwant for quantum transport calculation
[Python] I tried substituting the function name for the function name
I tried python programming for the first time.
I tried using the Datetime module by Python
[Python] I tried using OpenPose
I tried Python on Mac for the first time.
I tried python on heroku for the first time
I tried using Thonny (Python / IDE)
I tried using the checkio API
[Python] I tried using YOLO v3
I tried using the Python library from Ruby with PyCall
[Python] I tried collecting data using the API of wikipedia
[For beginners] I tried using the Tensorflow Object Detection API
I tried tensorflow for the first time
I tried using Bayesian Optimization in Python
I tried using UnityCloudBuild API from Python
Python: I tried the traveling salesman problem
I tried the Python Tornado Testing Framework
I tried using the BigQuery Storage API
I tried using parameterized
I tried "smoothing" the image with Python + OpenCV
I tried using argparse
I checked the library for using the Gracenote API
I tried using mimesis
I tried logistic regression analysis for the first time using Titanic data
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
I tried using anytree
I tried web scraping using python and selenium
I tried "differentiating" the image with Python + OpenCV
I tried using aiomysql
I tried object detection using Python and OpenCV
I tried using Summpy
I tried Python> autopep8
I tried simulating the "birthday paradox" in Python
I tried the least squares method in Python
I tried using PyCaret at the fastest speed
I tried using coturn
I tried using Pipenv
I tried using the Google Cloud Vision API
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using mecab with python2.7, ruby2.3, php7
I tried using ESPCN
I tried using openpyxl
[Python] I searched for the longest Pokemon Shiritori
I tried "binarizing" the image with Python + OpenCV
I tried using Ipython
I tried using PyCaret
I tried reading a CSV file using Python
I tried using cron
I tried using "Streamlit" which can do the Web only with Python
I tried Mind Meld for the first time
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
[Text classification] I tried using the Attention mechanism for Convolutional Neural Networks.
I tried using firebase for Django's cache server