这并不是严格意义上的答案,而是我对讨论的贡献
我用的是profiler
调查代码的稍微修改版本:
N_arr = 200:400:3800; %// for medium to large sized input array
for k1 = 1:numel(N_arr)
A = randi(1,N_arr(k1));
[~]=eq(A,0);
clear A
A = randi(1,N_arr(k1));
[~]=not(A);
clear A
end
我使用了以下探查器标志(根据未记录的 Matlab 系列帖子Profiler http://undocumentedmatlab.com/blog/undocumented-profiler-options):
profile('-memory','on');
profile('on','-detail','builtin');
And here's an excerpt from the profiler results (link to the larger image https://i.stack.imgur.com/Wbufb.png):
看来==
变体分配了一点点额外的内存,使其能够发挥其魔力......
关于你的问题2:在删除保留之前timeall
,我尝试绘制与您在 Excel 中所做的相同的图表。我没有观察到你提到的行为N = 320
。我怀疑这可能与您在代码中使用的附加包装器(即函数句柄)有关。
我想我应该附上所讨论功能的可用文档以供快速参考。
的文档~
(\MATLAB\R20???\toolbox\matlab\ops\not.m):
%~ Logical NOT.
% ~A performs a logical NOT of input array A, and returns an array
% containing elements set to either logical 1 (TRUE) or logical 0 (FALSE).
% An element of the output array is set to 1 if A contains a zero value
% element at that same array location. Otherwise, that element is set to
% 0.
%
% B = NOT(A) is called for the syntax '~A' when A is an object.
%
% ~ can also be used to ignore input arguments in a function definition,
% and output arguments in a function call. See "help punct"
% Copyright 1984-2005 The MathWorks, Inc.
的文档==
(\MATLAB\R20???\toolbox\matlab\ops\eq.m):
%== Equal.
% A == B does element by element comparisons between A and B
% and returns a matrix of the same size with elements set to logical 1
% where the relation is true and elements set to logical 0 where it is
% not. A and B must have the same dimensions unless one is a
% scalar. A scalar can be compared with any size array.
%
% C = EQ(A,B) is called for the syntax 'A == B' when A or B is an
% object.
% Copyright 1984-2005 The MathWorks, Inc.