Running the Profiler can be done in two ways:
Clicking the "Run and Time" button in the MATLAB GUI while having some
.m file open in the editor (added in R2012b).
profile on <some code we want to test> profile off
Below is some sample code and the result of its profiling:
function docTest for ind1 = 1:100 [~] = var(... sum(... randn(1000))); end spy
From the above we learn that the
spy function takes about 25% of the total execution time. In the case of "real code", a function that takes such a large percentage of execution time would be a good candidate for optimization, as opposed to functions analogous to
cla whose optimization should be avoided.
Moreover, it is possible to click on entries in the Function Name column to see a detailed breakdown of execution time for that entry. Here's the example of clicking
It is also possible to profile memory consumption by executing
profile('-memory') before running the Profiler.