why slow 5 times when tic or toc and expression in one line?
Mostra commenti meno recenti
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 Commenti
Stephen23
il 20 Mar 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
il 20 Mar 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.
Risposta accettata
Più risposte (1)
Binbin Qi
il 20 Mar 2015
0 voti
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!