Skip to Main Content Skip to Search
Product Documentation

toc - Stop clock to measure performance

Syntax

toc
toc(ticID)
elapsedTime = toc
elapsedTime = toc(ticID)

Description

toc stops a stopwatch timer started by the tic function, and displays the time elapsed in seconds.

toc(ticID) displays the time elapsed since the tic command corresponding to ticID.

elapsedTime = toc stores the elapsed time in a variable.

elapsedTime = toc(ticID) stores in a variable the time elapsed since the tic command corresponding to ticID.

Tips

Input Arguments

ticID

Identifier generated by a previous call to tic with an output argument.

Output Arguments

elapsedTime

Scalar double representing the time elapsed between tic and toc commands, in seconds.

Examples

Measure how the time required to solve a linear system varies with the order of a matrix:

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)
 

Measure the minimum and average time to compute a summation of Bessel functions:

REPS = 1000;   minTime = Inf;   nsum = 10;
tic;

for i=1:REPS
   tStart = tic;   total = 0;
   for j=1:nsum, 
      total = total + besselj(j,REPS);
   end

   tElapsed = toc(tStart);
   minTime = min(tElapsed, minTime);
end
averageTime = toc/REPS;

See Also

clock | cputime | etime | profile | tic

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS