用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自带document《desktop tools and development
environment》