tic
Starts a stopwatch timer.
Category: Software Development Tools > Performance and Memory
Syntax
tic
Starts the timer. A later call to toc reports the time since this point.
t = tic
Starts the timer and returns an id that identifies this stopwatch.
Description
tic records the current moment and toc reads the elapsed wall-clock seconds from it. Without an output, tic stores the moment in a single shared timer, and each new tic replaces it.
The pair is meant for coarse timing of a block of code. For a reliable measurement of a fast function, timeit repeats the call and removes overhead.
Output arguments
t- Timer id, to be passed to
toc(t)when several stopwatches run at the same time.
Example
Timing a loop
tic
s = 0;
for k = 1:1e5
s = s + sqrt(k);
end
t = toc;
disp(t >= 0)
fprintf('%.2f\n', s)
Output
1
21082008.97