I have a relatively big code and I would like to use "profile" to improve it. When I use "profile" I got a report listing all the functions (built in's, and my .m functions) and their respective running time.
我有一个相对较大的代码,我想使用“配置文件”来改进它。当我使用“profile”时,我得到了一份报告,列出了所有功能(内置和我的.m功能)及其各自的运行时间。
I would like to list just functions written by myself (not the built in's) and their respective running time. Anyone knows how to do that??
我想列出我自己编写的函数(不是内置函数)和它们各自的运行时间。谁知道怎么做?
Thanks in advance.
提前致谢。
2 个解决方案
#1
Are you looking at the Profile Summary? If so, then there is a column listing total time and self time for each function (including your own). I think self time may be the time you are looking for. Also, you can click on the function name in the left most column and see the details of how the time was spent in the code. Be sure to check the Show Function listing box and refresh to see the timing detail on each line of the code. I hope this helps.
您是否在查看个人资料摘要?如果是这样,那么列表列出了每个功能的总时间和自我时间(包括您自己的功能)。我认为自我时间可能是你正在寻找的时间。此外,您可以单击最左侧列中的函数名称,并查看代码中花费时间的详细信息。请务必检查“显示函数”列表框并刷新以查看代码每行的时序详细信息。我希望这有帮助。
#2
Here is a try, using the 'info'
parameter of the profile
function. I am discarding Matlab functions by comparing their complete path name with matlabroot
. Here is the code:
这是一个尝试,使用配置文件功能的'info'参数。我通过比较他们的完整路径名与matlabroot来丢弃Matlab函数。这是代码:
profile on
... % Put the code to profile here
% Stop the profiler and get infos
stats = profile('info');
% Sort results based on the total execution time
[~,I] = sort([stats.FunctionTable.TotalTime], 'descend');
for i = I
% Get file structure
F = stats.FunctionTable(i);
% Discard Matlab functions
if ~isempty(findstr(F.CompleteName, matlabroot))
continue;
end
% Display the total execution time and the function name
fprintf('%.06f sec\t', F.TotalTime);
fprintf('%s\n', F.FunctionName);
end
Although the profiler gives a representation that looks much nicer, this does accomplish what you set out to do.
虽然分析器提供的表示看起来更好,但这确实完成了您的目标。
NB: At first I thought I could use the output of the exist
function, but only a core subset of Matlab functions are labeled 'builtin'. For instance repmat
and verLessThan
have the same flag as custom functions, and are therefore not considered to be built-in.
注意:起初我以为我可以使用存在函数的输出,但只有Matlab函数的核心子集被标记为'builtin'。例如,repmat和verLessThan具有与自定义函数相同的标志,因此不被视为内置函数。
Best,
#1
Are you looking at the Profile Summary? If so, then there is a column listing total time and self time for each function (including your own). I think self time may be the time you are looking for. Also, you can click on the function name in the left most column and see the details of how the time was spent in the code. Be sure to check the Show Function listing box and refresh to see the timing detail on each line of the code. I hope this helps.
您是否在查看个人资料摘要?如果是这样,那么列表列出了每个功能的总时间和自我时间(包括您自己的功能)。我认为自我时间可能是你正在寻找的时间。此外,您可以单击最左侧列中的函数名称,并查看代码中花费时间的详细信息。请务必检查“显示函数”列表框并刷新以查看代码每行的时序详细信息。我希望这有帮助。
#2
Here is a try, using the 'info'
parameter of the profile
function. I am discarding Matlab functions by comparing their complete path name with matlabroot
. Here is the code:
这是一个尝试,使用配置文件功能的'info'参数。我通过比较他们的完整路径名与matlabroot来丢弃Matlab函数。这是代码:
profile on
... % Put the code to profile here
% Stop the profiler and get infos
stats = profile('info');
% Sort results based on the total execution time
[~,I] = sort([stats.FunctionTable.TotalTime], 'descend');
for i = I
% Get file structure
F = stats.FunctionTable(i);
% Discard Matlab functions
if ~isempty(findstr(F.CompleteName, matlabroot))
continue;
end
% Display the total execution time and the function name
fprintf('%.06f sec\t', F.TotalTime);
fprintf('%s\n', F.FunctionName);
end
Although the profiler gives a representation that looks much nicer, this does accomplish what you set out to do.
虽然分析器提供的表示看起来更好,但这确实完成了您的目标。
NB: At first I thought I could use the output of the exist
function, but only a core subset of Matlab functions are labeled 'builtin'. For instance repmat
and verLessThan
have the same flag as custom functions, and are therefore not considered to be built-in.
注意:起初我以为我可以使用存在函数的输出,但只有Matlab函数的核心子集被标记为'builtin'。例如,repmat和verLessThan具有与自定义函数相同的标志,因此不被视为内置函数。
Best,