The following code is slowing down my application considerably:
N = 25000;tic; a=cell(N,1); for k = 1:N, a{k} = @sum; end, toc;tic; clear a; toc;y=1;tic; a=cell(N,1); for k = 1:N, a{k} = @(x)sum(x,y); end, toc;tic; clear a; toc;
While the first CLEAR took 0.4 seconds, the last CLEAR took 40 seconds on my machine:
Elapsed time is 0.232545 seconds. Elapsed time is 0.392423 seconds. Elapsed time is 1.775241 seconds. Elapsed time is 40.111263 seconds.
Why does clearing references to anonymous functions with no input arguments require considerably less time than clearing references to anonymous functions with input arguments from the base workspace?
Best Answer