Matlab Profiler为什么说“for”循环的“结束”语句存在瓶颈? [英] Why does the Matlab Profiler say there is a bottleneck on the 'end' statement of a 'for' loop?

查看:169
本文介绍了Matlab Profiler为什么说“for”循环的“结束”语句存在瓶颈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我最近开始定期使用Matlab的内置分析器,而且我注意到,虽然它通常很好地显示哪些线路占用最多的时间,但有时它会告诉我一个大的在语句的 end 语句中用于循环。



现在,看到这样的一行只是用来表示循环的结束,我无法想象如何使用除了一个微不足道的处理以外的任何东西。



我已经看过这个问题的具体版本问上 matlab中央,但似乎没有达成共识。

编辑:这是一个这个问题的最小的例子:

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

即使取消注释 clear end 行仍然占用大量的计算量(大约20%), clear 增加了结束行计算的绝对数量。

解决方案

当我在代码中看到这个时,释放循环中创建的大临时对象。在循环中创建的每个新变量都在 end 处释放。


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.

解决方案

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.

这篇关于Matlab Profiler为什么说“for”循环的“结束”语句存在瓶颈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆