我有一个函数,反过来调用更多的函数。我想使用分析器来确定代码的哪些部分最需要时间。
是否可以获取配置文件摘要按单元格排序,而不是函数调用?
例如,是否可以让分析器输出:
Cells Calls Total time ...
Part 1 1 .... ...
Part 2 1 .... ...
而不是:
Function name Calls Total time ...
func1 1 .... ...
func2 1 .... ...
以下代码:
%% Part 1:
a = 1;
b = 2;
X = func1(a,b);
%% Part 2:
c = a+b;
Y = func2(c,b);
谢谢!
答案 0 :(得分:2)
嗯,您可以随时提取每个单元格的分析信息,如下所示:
%% Part 1
profile on
%// Some code...
profile off
S1 = profile('info');
%% Part 2
profile on
%// Some more code...
profile off
S2 = profile('info');
结构S1
和S2
应保存每个单元格的分析信息。请记住在每个代码单元的开头和结尾放置profile on
和profile off
以重置分析信息。
要以HTML格式查看个人资料信息,您可以使用profview
。例如:
profview(0, S1)
第一个参数是配置文件信息结构的FunctionTable
字段中的索引,它对应于要在配置文件查看器中显示的功能。