Timeit on pause(2) returns weird ouput

3 ビュー (過去 30 日間)
Torkel Loman
Torkel Loman 2022 年 2 月 28 日
回答済み: Peter Perkins 2022 年 3 月 2 日
I am trying to get the timeit function to work.I read https://uk.mathworks.com/help/matlab/ref/timeit.html and get the example:
X = rand(100);
f = @() svd(X);
t1 = timeit(f)
I want to try this using the pause(2), since this should take about 2 seconds:
g = @() pause(2);
t2 = timeit(g)
the output is
t2 =
3.4639e-06
which is a lot less than the expected 2 seconds. Clearly I am missunderstanding something (which probably makes my more serious attempts at using timeit also wrong), but what?

回答 (1 件)

Peter Perkins
Peter Perkins 2022 年 3 月 2 日
The issue is pause, not timeit:
"STATE = pause(...) returns the state of pause previous to processing the input arguments."
>> t2 = timeit(g,0)
t2 =
2.000208413333

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by