why slow 5 times when tic or toc and expression in one line?
Show older comments
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 Comments
Stephen23
on 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
on 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.
Accepted Answer
More Answers (1)
Binbin Qi
on 20 Mar 2015
0 votes
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!