Commands faster in one line
9 views (last 30 days)
Show older comments
When I run basic arithmetic, and simple memory allocation tasks in the command window (say matrix multiplication and variable assignment, why is it so much faster to run all the statements in a single line separated by semicolons rather than multiple line with a single tsatement on each? Example:
tic;A = rand(5);B = rand(5);C = A*B;toc
Elapsed time is 0.000039 seconds.
>> tic;
A = rand(5);
B = rand(5);
C = A*B;
toc
Elapsed time is 0.014997 seconds.
0 Comments
Accepted Answer
dpb
on 2 Jul 2014
Because at the command line each line is parsed and the JIT compiler/optimizer is pretty much disabled. In an m-file, the file is parsed and then executed.
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!