Why does the Matlab Profiler say there is a bottleneck on the 'end' statement of a 'for' loop?

ぐ巨炮叔叔 提交于 2019-11-27 06:44:32

问题


So, I've recently started using Matlab's built-in profiler on a regular basis, and I've noticed that while its usually great at showing which lines are taking up the most time, sometimes it'll tell me a large chunk of time is being used on the end statement of a for loop.

Now, seeing as such a line is just used for denoting the end of the loop, I can't imagine how it could use anything other than a trivial amount of processing.

I've seen a specific version of this question asked on matlab central, but a consensus didn't seem to be reached.

EDIT: Here's a minimal example of this problem:

for i =1:1000
    x = 1;
    x = [x 1];
    % clear x;
end

Even if you uncomment the clear, the end line still takes up a lot of computation (about 20%), and the clear actually increases the absolute amount of computation performed by the end line.


回答1:


When I've seen this in my code, it's been the deallocation of large temporaries created in the loop. Each new variable created in the loop is deallocated at the end.



来源:https://stackoverflow.com/questions/6905809/why-does-the-matlab-profiler-say-there-is-a-bottleneck-on-the-end-statement-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!