Commands faster in one line
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
dpb
2014-7-2
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!