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.
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.
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:
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.
Best,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With