# toc

Stop the internal timer

### dt = toc

• It stops the internal timer, and reports the elapsed time since the last call of tic.
• The elapsed time reported is in seconds, and is derived from the CPU time (Mach absolute time).

### dt = toc(t)

• The input t should be obtained by calling t = tic.
• The output dt is the elapsed time (seconds) between the time t and the time when toc(t) is called.

Example 1: The following code was run on an iPhone 6 Plus. The elapsed times reported were measured from the same starting time when tic was called.

tic
a=rand(1000,1000);
b=rand(1000,1000);
toc
C=a'.*b';
toc

Time elapsed: 2.371719 seconds
Time elapsed: 7.204703 seconds


Example 2: Time (in seconds) required to solve a system of n equations on an iPhone 6S.

clear
t=zeros(1,100);
for n=1:100
a=rand(n,n);
b=rand(n,1);
tic;
x=a\b;
t(n)=toc;
end
plot(t)
xlabel('n');
ylabel('Time needed');
title('Time required to solve a system of n linear equations')