why slow 5 times when tic or toc and expression in one line?
Mostrar comentarios más antiguos
when tic or toc and the main expression are in one line, it will be slow 5 times than not in a line
1: tic or toc and the expression in one line
tic;for k = 1:9e7;a = plus(1,1);end;toc
2. not in one line
tic;
for k = 1:9e7;a = plus(1,1);end;
toc
Elapsed time is 0.974705 seconds.
Elapsed time is 0.187138 seconds.
2 comentarios
Stephen23
el 20 de Mzo. de 2015
On MATLAB 2010b:
% 1: tic or toc and the expression in one line
tic;for k = 1:9e7;a = plus(1,1);end;toc
% 2. not in one line
tic;
for k = 1:9e7;a = plus(1,1);end;
toc
prints:
Elapsed time is 0.818340 seconds.
Elapsed time is 0.813082 seconds.
Michael Haderlein
el 20 de Mzo. de 2015
Same code, output:
Elapsed time is 28.378463 seconds.
Elapsed time is 27.739867 seconds.
Comparison of the values indicates no difference between the two cases. Absolute values indicate that I want a new computer.
Respuesta aceptada
Más respuestas (1)
Binbin Qi
el 20 de Mzo. de 2015
0 votos
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!