Why do I encounter performance issues while executing FOR-loops with complex numbers?
显示 更早的评论
When I execute the following code:
nd =1600 ;nfc = 800;
M = repmat( diag( fft(eye(nfc)) ).',[nd 1]);
tic % Copy M into F, using a forward loop
F = zeros(nd, nfc);
for kf=1:nfc
F(:,kf) = M(:,kf);
end
toc
The output is
Elapsed time is 0.11 seconds
Now when a reverse loop is used as follows,
tic
F = zeros(nd, nfc);
% Copy M into F, reverse loop
for kf=nfc:-1:1
F(:,kf) = M(:,kf);
end
toc
the output is
Elapsed time is 12.93 seconds
which is more than 100 hundred times the timing obtained in the first case.
Indicating that, the FOR-loop execution time differs from forward loop to reverse loop.However the timings are consistent with real numbers, as shown below:
M = real(M); % transform M into real numbers
tic % Forward loop
F = zeros(nd, nfc);
for kf=1:nfc
F(:,kf) = M(:,kf);
end
toc
gives
Elapsed time is 0.06 seconds
And,
tic % Reverse loop
F = zeros(nd, nfc);
for kf=nfc:-1:1
F(:,kf) = M(:,kf);
end
toc
also gives
Elapsed time is 0.06 seconds
采纳的回答
更多回答(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!