23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Analyzing Your Program’s Performance<br />

Keep in mind that tic and toc measure overall elapsed time. Make sure that<br />

no other applications are running in the background on your system that<br />

could affect the timing of your <strong>MATLAB</strong> programs.<br />

Measuring Smaller Programs<br />

Shorter programs sometimes run too fast to get useful data from tic and toc.<br />

When this is the case, try measuring the program running repeatedly in a<br />

loop, and then average to find the time for a single run:<br />

tic<br />

for k = 1:100<br />

-- run the program --<br />

end<br />

toc<br />

Using tic and toc Versus the cputime Function<br />

Although it is possible to measure performance using the cputime function,<br />

it is recommended that you use the tic and toc functions for this purpose<br />

exclusively. It has been the general rule for CPU-intensive calculations run<br />

on Windows machines that the elapsed time using cputime and the elapsed<br />

time using tic and toc are close in value, ignoring any first time costs.<br />

There are cases however that show a significant difference between these<br />

two methods. For example, in the case of a Pentium 4 with hyperthreading<br />

running Windows, there can be a significant difference between the values<br />

returned by cputime versus tic and toc.<br />

11-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!