Why the function "timeit" doesn't work correctly

Help_please
I have a problem in function timeit (also tic toc) in matlab R2016a , it dsesn't calculate the correct time , for exemple: the result supposed to be: 4,.... seconds but it gives always 0,3....(the same code give a correct answer but in Matlab 2014)

1 件のコメント

Jan
Jan 2022 年 8 月 7 日
What is your question? It is not clear, why you expect a specific runtime. Without any details it is impossible to answer.

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

 採用された回答

Jan
Jan 2022 年 8 月 7 日

1 投票

timeit and tic/toc measure the runtime. If they determine a runtime of 4 seconds in Matlab R2014 and just 0.3 seconds in Matlab R2016a, this means, that Matlab works faster for the concerned results.
Remember, that the new graphics engine HG2 was introduced in R2014b. Maybe tic/toc measures the time before a complicated figure is rendered. So insert a drawnow in your code.
As said alread: As long as you do not mention any details about the code, it is impossible to understand, why you assume a problem. Post some code, which reproduces the problem and a more explicit explanation is possible.

3 件のコメント

Sihem
Sihem 2022 年 8 月 7 日
I have programmed the genetic algorithm for a scheduling problem, i see that's a problem cause when i calculate the time with a chronometer it gives me 4 seconds !! not 0, ...
Walter Roberson
Walter Roberson 2022 年 8 月 8 日
編集済み: Walter Roberson 2022 年 8 月 8 日
timeit() will usually run the function multiple times, in order to reduce measurement noise. (If the initial run takes more than a particular hard-coded amount of time then timeit() will just report that time rather than running several invocations.)
The design of the original timeit is discussed at https://blogs.mathworks.com/steve/2008/02/29/timing-code-in-matlab/
Jan
Jan 2022 年 8 月 8 日
@Sihem: I have no idea how we can help you, if you insist on not explaining any details.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2022 年 8 月 7 日

コメント済み:

Jan
2022 年 8 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by