Unfortunately, I could not find anything specific on this subject. However, anonymous functions must have additional overhead compared to regular functions.
You can try it yourself. First create a filenonanon.m
function x=nonanon(y)
x=y^2;
end
Then create the cell file with:
%% non anon
tic
for i=1:1000000
z=nonanon(i);
end
toc
%% anon
f=@(x) x^2;
tic
for i=1:1000000
z=f(i);
end
toc
enjoy, exit:
Elapsed time - 0.513759 seconds.
The elapsed time is 14.434895 seconds.
Which concludes that anonymous functions are slower.
user677656
source
share