MATLAB Answers

John Doe

Strange results from tic / toc.

Asked by John Doe
on 9 May 2013
Accepted Answer by cr

I'm checking the running time of a function using tic/toc. I write the following in the command window (and execute it simultaneously):

res = checkFunc('case2736sp',1:3000);
Elapsed time is 0.080491 seconds.

where checkFunc returns a 2736x2500 full matrix.

What puzzles me is that I have to wait almost 20 seconds for the output saying the run time is only 80 ms.

Does anyone have a clue why this is?



No products are associated with this question.

1 Answer

Answer by cr
on 9 May 2013
Edited by cr
on 9 May 2013
 Accepted answer

Are you sure 'checkFunc' does NOT do a tic somewhere in its code? Anyways, this would be a better way to test:

tx = tic; res = checkFunc('case2736sp',1:3000); toc(tx)

  1 Comment

You're of course right =) Thanks!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!