Performances of nested functions
이전 댓글 표시
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!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!