Warning on PERSISTENT statement
조회 수: 6 (최근 30일)
이전 댓글 표시
I know that PERSISTENT statement is slow, and try to overcome by passing an logical argument to by-pass when I know the function doesn't need using the persistent variable. This illustrate by my FOO function
function a = foo(astatic)
if astatic
% mlint: "PERSISTENT could be very inefficient unless it is a top-level
% statement in its function"
persistent A
a = A;
else
a = 3;
end
end % of foo
But then MATLAB gives the warning I quote abobe.
To clear thing out, I made a comparison of runing time with BAR function
function a = bar(astatic)
% No warning
persistent A
if astatic
a = A;
else
a = 3;
end
end % of bar
And then when I test (R2019a, windows) I get those results
tic;
for k=1:1000000
foo(0);
end
toc % Elapsed time is 0.076238 seconds.
%%
tic;
for k=1:1000000
foo(1);
end
toc % Elapsed time is 0.784971 seconds.
%%
tic;
for k=1:1000000
bar(0);
end
toc % Elapsed time is 0.764904 seconds.
%%
tic;
for k=1:1000000
bar(1);
end
toc % Elapsed time is 0.790119 seconds.
As you can see, the results do not backup MLINT message.
Can I just ignore it or is there anything else I miss?
댓글 수: 4
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!