通过删除全部清除来提高性能 [英] Increase the performance by removing CLEAR ALL
问题描述
在Matlab 2014b
中,当我在脚本开头使用CLEAR ALL
时,收到以下警告,
For improved performance, consider not using CLEAR ALL within a script
在以前的版本中没有提供(我记得).
我发现的唯一原因是,当您从外部或其他脚本中调用脚本时,您不想清除工作空间中的变量,而是一次又一次地重新生成它们.
我还有其他原因吗?
使用单个脚本时,删除CLEAR ALL
如何提高性能?
在R2015b中,clear
的语义已更改.也许是为了回答此问题引起的关注,声明了更改发行说明中的是:
clear
函数不再清除调试断点.要清除断点,请使用dbclear all
.
clear
功能仅清除当前未运行的功能.例如,当您在myFun
运行时调用clear myFun
时,不会清除myFun
.
此部分与R2015b之前的MATLAB版本有关.
这是一张表格,其中列出了每项要清除的内容输入参数.
R2015b的表相同,只是不再有调试断点"列,因为它们不再使用clear
清除.
当您可能只按clear variables
(红色框)时,脚本和功能便被清除.从当前正在执行的内存中清除功能没有多大意义. (根据R2015b发行说明,这不会发生.)
还要记住,脚本在基本工作区中执行,所以您要清除其他脚本可能使用的所有功能.在扩展的MATLAB修补会话之后,尝试查看inmem
的输出.您可以找到加载到内存中以进行快速访问的各种MATLAB函数(包括'matlabrc'
,'pathdef'
和其他用于设置工作区的核心脚本).因此,也许不是因为它损害了您调用clear all
的脚本的性能,而是损害了所有其他脚本以及基本工作区中的交互式命令行.这是我的猜测. >
与性能无关,但是脚本中的clear all
可能不是一个好主意的另一个原因是它将清除断点(这可能很烦人!)以及全局+持久变量.但是,清除全局变量和持久变量可能是目标.对于全局变量,有clear global
,但是对于持久性而言,没有什么比这更好的了,因为持久性变量已绑定到函数,并且您将对它们使用clear functions
或clear whateverFunctionName
.
In Matlab 2014b
, when I use CLEAR ALL
at the beginning of the script I get the following warning,
For improved performance, consider not using CLEAR ALL within a script
which is not given in the previous releases (As I recall).
The only reason I found is that, when you call a script from outside or from other scripts you do not want to clear the variables in the workspace, and re-generate them every time again and again.
Is there any other reason that I am missing?
How does removing CLEAR ALL
improves the performance when using a single script?
In R2015b, the semantics of clear
were changed. Perhaps in response to the concerns raised in this question, the changes stated in the release notes are:
The
clear
function no longer clears debugging breakpoints. To clear breakpoints, usedbclear all
.The
clear
function only clears functions that are not currently running. For example, when you callclear myFun
whilemyFun
is running,myFun
is not cleared.
This part pertains to pre-R2015b MATLAB versions.
Here's a table of what gets cleared with each input argument.
The table for R2015b is identical except that there is no longer a "Debugging breakpoints" column since they are no longer cleared with clear
.
Scripts and functions are cleared, when you can probably just clear variables
(red boxes). It does not make a lot of sense to clear the function from memory that is presently being executed. (According to R2015b release notes, this does not happen.)
Also, keeping in mind that scripts execute in the base workspace, you are clearing out all functions that may be used by other scripts. Try looking at the output of inmem
after an extended MATLAB tinkering session. You fill find all kinds of MATLAB functions that are loaded into memory for fast access (including 'matlabrc'
, 'pathdef'
, and other core scripts that setup your workspace). So, perhaps it's not that it hurts performance of just the script where you call clear all
but all other scripts and the interactive command line that is in the base workspace. That would be my guess.
Not performance related, but another reason why a clear all
in a script might be a bad idea is that it will clear breakpoints (this can be annoying!), and global+persistent variables. However, it might be the goal to clear global and peristent variables. For global there's clear global
, but there's nothing like that for persistent since persistent variables are bound to functions and you would use clear functions
or clear whateverFunctionName
for them.
这篇关于通过删除全部清除来提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!