PYTHON cProfile
来源:互联网 发布:windows键盘command键 编辑:程序博客网 时间:2024/05/19 17:56
Python性能监控之:cProfile
Python内置监控模块cProfile可以监控程序内耗,对性能分析很有帮助。相关的还有profile、pstats、timeit和hotshot,cProfile可以检测到中断并保存数据。如下test.py:
times = 1000000def foo():
sum = 0
for i in range(10):
sum += 1
sum = 0
def useFoo():
foo()
def app1():
global times
for i in range(times):
foo()
def app2():
global times
for i in range(times):
useFoo()
app1()
app2()
执行:python -m cProfile -s time test.py 结果如下:
5000008 function calls in 26.522 CPU seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
2000000 11.705 0.000 16.949 0.000 test.py:2(foo)
2000002 5.306 0.000 5.306 0.000 {range}
1000000 4.796 0.000 14.812 0.000 test.py:8(useFoo)
1 2.732 2.732 17.566 17.566 test.py:17(app2)
1 1.982 1.982 8.954 8.954 test.py:12(app1)
1 0.001 0.001 26.522 26.522 {execfile}
1 0.000 0.000 26.520 26.520 test.py:1(<module>)
1 0.000 0.000 26.522 26.522 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
示例代码执行了两个函数,其中一个只是调用另一个。结果除了反应出程序各模块的耗时之外,也反应出Python函数调用的耗时:本示例中函数调用耗时多了一倍。
另外有一个带GUI的工具VisualPyTune (vpt) ,支持profile、cProfile、hotspot和timeit,小试了一下截个图:
- PYTHON cProfile
- Python脚本性能剖析-cprofile
- 应用python的性能测量工具cProfile
- 应用python的性能测量工具cProfile
- Profiling Python using cProfile: a concrete case
- 使用cProfile分析Python程序性能
- python性能分析工具:cProfile使用
- Python中cProfile性能分析工具的使用
- 使用memory_profiler 与 cProfile ,line_profiler 优化Python程序运行时间和内存消耗实例
- FEC CProfile 使用
- Python的7种性能测试工具:timeit、profile、cProfile、line_profiler、memory_profiler、PyCharm图形化性能测试工具、objgraph
- 性能分析器cProfile、line_profiler、memory_profiler
- Python
- Python
- Python
- python
- Python
- PYTHON
- sqlite3_open_v2(“/data/data/com.android.packagename/databases/dump.sqlite”, &handle, 1, NULL) failed
- 成员函数指针与高效C++委托 (delegate)
- javaBean和Servlet的区别
- PHP网站架构工具箱
- 为什么需要Backbone.js?
- PYTHON cProfile
- oracle EM的创建于配置
- 常见HTTP攻与防
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- Android中获取系统内存信息以及进程信息-----ActivityManager的使用(一)
- 图片服务器选型方案
- mianshi - 记录 2013-03-28
- 水利防汛之水库和河道预警SQL语句
- GPS最新资料大全