Timeit on pause(2) returns weird ouput

2 visualizaciones (últimos 30 días)
Torkel Loman
Torkel Loman el 28 de Feb. de 2022
Respondida: Peter Perkins el 2 de Mzo. de 2022
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?

Respuestas (1)

Peter Perkins
Peter Perkins el 2 de Mzo. de 2022
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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by