Why do I encounter performance issues while executing FOR-loops with complex numbers?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!