Why is tic/toc not reporting the correct elapsed time?
Afficher commentaires plus anciens
I'm trying to time how long it takes for my program to run and tic/toc is reporting an elapsed time of 150 seconds, but when I time it with a stopwatch, it actually takes 3 hours and 24 minutes for my program to run.
Why is there such a significant discrepancy?
4 commentaires
madhan ravi
le 13 Août 2019
mind attaching the file?
Ewen Chan
le 13 Août 2019
Walter Roberson
le 13 Août 2019
Are you saving the result of tic() into a variable and toc() against the variable? If not then you might have another tic() call that is interfering: toc() reports relative to the most recent tic() that had no output.
Ewen Chan
le 13 Août 2019
Réponses (1)
Bruno Luong
le 13 Août 2019
Modifié(e) : Bruno Luong
le 13 Août 2019
I never have problem with tic/toc. I believe it inquires CPU frequency/counter or clock and derive time from it. It's very direct and simple.
If you get some strange result, then as Walter said something must trigger a later tic when you are not expected.
It might be also safter using tic/toc with timerVal
t0 = tic();
...
dt = toc(t0)
if you are not sure about what happens during "..."
1 commentaire
Ewen Chan
le 13 Août 2019
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!