Performances of nested functions
Show older comments
Hi,
I'm new to matlab, so I hope I'm doing this right. I tried to find a documentation about performances of nested functions, but I haven't found something satisfying for my concern.
I ran this simple code on my system (winXP, MATLAB R2010a):
function [] = testNestedFunctions()
tic;
A = 0;
for i = 1:1000000
A = i * i;
end
toc;
tic;
A = 0;
for i = 1:1000000
A = nestedFun(i);
end
toc;
function [res] = nestedFun (i)
res = i * i;
end
end
The non nested code runs in 0.002511 seconds. The code with nested functions runs in 0.198646 seconds.
Is there a reason about this significant time difference? I thought it may be related to the use of loops, which may be not optimized using the nested function, but I didn't find any information about that.
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!