【脚本语言系列】关于Python代码分析工具line_profiler,你需要知道的事
2017-04-21 16:45
916 查看
如何使用line_profiler逐行分析
使用easy_install进行安装easy_install line_profiler
使用pip进行安装
pip install line_profiler
安装开发版本
1. 使用git签出(check out)源代码
git clone https://github.com/rkern/line_profiler.git
2. 签出源代码后,用如下方式构建并安装
python setup.py install
编写可供分析的代码
编写一个脚本,用来计算一系列不同大小的包含随机数的矩阵的平方。
同时要求对应的线程能休眠几秒钟。
待分析的函数需要用@profile进行标记。
import numpy import time @ profile def multply(n): A = numpy.random.rand(n, n) time.sleep(numpy.random.randint(0,2)) return numpy.matrix(A) ** 2 for n in 2 ** numpy.arrange(0, 10): multply(n)
对代码进行分析
kernprof -l -v mat_mult.py
Line# | Hits | Time | Per Hit | % Time | Line Contents |
---|
什么是line_profiler
line_profiler可以对Python代码进行逐行分析。相关文章推荐
- 【脚本语言系列】关于Python性能分析工具timeit, 你需要知道的事
- 【脚本语言系列】关于Python代码包/代码库搜索,你需要知道的事
- 【脚本语言系列】关于Python测试工具lettuce, 你需要知道的事
- 【脚本语言系列】关于Python网络分析Scapy,你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- 【脚本语言系列】关于Python测试工具docstrings, 你需要知道的事
- 【脚本语言系列】关于Python游戏工具Pygame,你需要知道的事
- 【脚本语言系列】关于Python测试工具Pylint, 你需要知道的事
- 【脚本语言系列】关于 Python 数据分析,你需要知道的事
- 【脚本语言系列】关于Python统计分析statsmodel,你需要知道的事
- 【脚本语言系列】关于Python安装代码包,你需要知道的事
- 【脚本语言系列】关于Python测试工具unittest, 你需要知道的事
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 【脚本语言系列】关于Python算法分析,你需要知道的事
- 【脚本语言系列】关于Python音频处理DirectSound, 你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLite,你需要知道的事
- 【脚本语言系列】关于Python文本解析HTML,你需要知道的事
- 【脚本语言系列】关于PythonGUI界面PythonWin,你需要知道的事
- 【脚本语言系列】关于PythonWeb访问urllib,你需要知道的事