Commands faster in one line

5 次查看(过去 30 天)
Patrick
Patrick 2014-7-2
评论: dpb 2014-7-2
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.

采纳的回答

dpb
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.
  2 个评论
Patrick
Patrick 2014-7-2
Ah, so parsing is the rate limiting step here? whereas in an m file, the whole thing is only parsed once, so it doesn't suffer from this same effect?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by