Why is tic/toc not reporting the correct elapsed time?

41 ビュー (過去 30 日間)
Ewen Chan
Ewen Chan 2019 年 8 月 13 日
コメント済み: Ewen Chan 2019 年 8 月 13 日
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 8 月 13 日
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
Ewen Chan 2019 年 8 月 13 日
To be honest, I'm not really sure. I have just been reassigned, so the code is new to me.
What I'm doing is I've wrapped the execution command with tic/toc.
The code times itself and generates a summary automatically for the actual runtimes, but I'm still not sure about the finer workings of it as it is a very complicated multi-system code. There's a LOT to it.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2019 年 8 月 13 日
編集済み: Bruno Luong 2019 年 8 月 13 日
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 件のコメント
Ewen Chan
Ewen Chan 2019 年 8 月 13 日
I'll try this today and hopefully, it'll produce a result that's more in line with the internal timers that have been built into the code/program itself.
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by