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.
vprof is a Python package that provides interactive visualization of profile information.
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.
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())
$ 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.
To be honest, the list displayed by cprofile may be easier to process and see. .. ..
memory stats
Memory usage is visualized.
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.
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