用profile可解决的问题:
1、避免不必要的计算
2、改动代码避免耗时的函数
3、储存一定的结果,避免重复计算
profile用作调试工具:
1、查找出没有实际运行的代码
2、You can also view the lines that did not run to help you
develop test cases
that exercise that code
3、当M文件中有错误时,从profile中查看什么运行了,什么没有运行。
profile用于理解M文件:
1、对于一个冗长的M文件,可以先用profile看看它是怎么运行的,那些行被实际调用了。
2、当你要编制一个与现存GUI或M文件相似的程序时,可以先运行profile查看那些是与你要实现的程序相似的部分。
profile的应用说明:
打开profile:(以下其一)
1、desktop——profiler
2、在打开的editor中,选tools——open
profiler
3、在历史命令窗口中,选择一些命令,右键选择profile
code。
4、命令窗口中,键入profile
viewer。
运行profiler
1、在run the code中键入命令——点击start
profiling。
2、profilingGUI时,点击start
profiling,清空run the code——打开GUI——合适的时候点击start
profiling——适用GUI结束后点击stop profiling
3、在命令窗口profiling:清空run the
code并点击start profiling——命令窗口键入运行的语句——运行结束后点击stop
profiling。
profiler报告的主要内容:
函数名;函数被调用次数;函数运行总时间(包含子函数);函数自身运行时间(不包含子函数);运行总时间图(函数运行总时间相对于整个时间)。
用matlab语言写的代码是解释执行的,并非如同C一样地用compiler一步步编译过来的,所以要分析matlab的程序,就很难用gprof和vtune来分析。这里,matlab里自带一个profile工具。简单来操作的话就是:
profile on
--打开profile
。。。
path一下
程序结束了以后
profile
report或profile viewer
--有profile的文件不想保存profile结果的话到这里就可以了
p = profile('info')
--产生p这个数据结构
profsave(p,'保存路径')
--保存了profile的结果.
profile
语法
1.profile on
启动事件探查器,清除以前记录个人资料的统计。
2.profile -timer
指定的时间来使用的类型。为时钟有效值如下:
profile -timer 'cpu'的 - 事件探查器使用计算机的时间(默认)。
profile -timer 'real' -
事件探查器使用墙上时钟时间。
3.profile off Matlab中文论坛
停止探查。
4.profile resume
没有清除以前的统计数字重新启动探查。
5.profile clear www.iLoveMatlab.cn
清除的个人资料记录的数字。
6.profile viewer
停止探查
并显示在窗口中的结果。