I have a code in which certain blocks are 'auxiliary' and others need to be measured for their running time. So it looks like:
function [out1, .., outN, time] = xyz(arg1, .., argN)[code 1]; % auxiliary
[code 2]; % time needs to be measured
[code 3]; % auxiliary[code 4]; % time needs to be measured
Btw, auxiliary means that this code is 'implementation specific' and doesn't constitute the main part of the algorithm.
I'd like to provide robust time estimates, which is possible with timeit(), but then anonymous functions need to be defined for every piece of code (afaik). This is not always easy to do…
Is there any known way to make timeit() work as tic .. toc, i.e. to make it measure the running time of arbitrary code pieces like e.g.:
L = Min; for i = 1:m L(i,i) = max(L(i,:)); end
Here it's unclear how to incorporate a loop into an anonymous function. Sometimes loops can be avoided, but sometimes not. Some other examples are probably possible.
Should I use tic .. toc in such situations?
Best Answer