Timeit on pause(2) returns weird ouput

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by