This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.


Start stopwatch timer


timerVal = tic


tic starts a stopwatch timer to measure performance. The function records the internal time at execution of the tic command. Display the elapsed time with the toc function.

timerVal = tic returns the value of the internal timer at the execution of the tic command, so that you can record time for simultaneous time spans.

Output Arguments


Value of the internal timer at the execution of the tic command. This value is used as an input argument for a subsequent call to toc. You should not rely on the meaning of this value.


Measure time to generate two random matrices and compute element-by-element multiplication of their transposes.

A = rand(12000, 4400);
B = rand(12000, 4400);
C = A'.*B';

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);
    x = A\b;
    t(n) = toc;

Measure multiple time spans simultaneously using two pairs of tic/toc calls. To do this, measure the minimum and average time to compute a summation of Bessel functions:

REPS = 1000;   minTime = Inf;   nsum = 10;
tic;  % TIC, pair 1

for i=1:REPS
   tStart = tic;  % TIC, pair 2  
   total = 0;
   for j=1:nsum 
      total = total + besselj(j,REPS);

   tElapsed = toc(tStart);  % TOC, pair 2  
   minTime = min(tElapsed, minTime);
averageTime = toc/REPS;  % TOC, pair 1  

More About

collapse all


  • Consecutive tic commands overwrite the internally recorded starting time.

  • The clear function does not reset the starting time recorded by a tic command.

  • The following actions result in unexpected output:

    • Using tic and toc to time timeit

    • Using tic and toc within a function timed by timeit

See Also

| | | | |

Introduced before R2006a

Was this topic helpful?