An open exchange for the MATLAB and Simulink user community |
Hosted by The MathWorks |
|
| Related Topics |
| New Products | Support | Documentation | Training | Webinars | Jobs | Newsletters |
| Problems? Suggestions? Contact us at files@mathworks.com | © 1994-2008 The MathWorks, Inc. Trademarks Privacy Policy |
Sometimes you want to time code that runs for a teeny fraction of a second, and
tic ;
dosomething ;
t = toc
is not accurate. The profiler will also be inaccurate. (You might want to time this teeny fraction of a second becaus you want to use the dosomething function zillions of times inside a larger application). Here is a trick I like to use
tic ;
t = 0 ;
ntrials = 0 ;
while (t < 1)
dosomething ;
ntrials = ntrials + 1 ;
t = toc ;
end
t = t / ntrials ;
That way, you run “dosomething” enough times to accumulate a whole second, and then you compute the average time per call to dosomething.
Tim, an excellent suggestion. I would want to make sure that the time for dosomething >> the rest of the code in loop. For most applications it would be.
Thanks,
Doug