Same code taking 15x longer to execute on a faster machine

4 visualizaciones (últimos 30 días)
Aiman Raza
Aiman Raza el 16 de Nov. de 2022
Comentada: Aiman Raza el 17 de Nov. de 2022
I recently upgraded to a faster computer (from a 16Gb i7 processor to a 32Gb RYZEN processor with a 16Gb NIVIDIA RTX GPU (CUDA compatible)).
I used to execute the following code in a matter of 5-10 seconds on my older machine (MATLAB 2021a). Now it is taking >2 minutes on a way faster machine (MATLAB 2022b).
I think it is related to a certain memory allocation setting in MATLAB which I might have applied on my previous machine, but I can't remember it anymore.
Is there someone who could help me in resolving this issue, please? For example, which setting I could modulate to execute this code faster?
Or is it is related to the MATLAB version?
dE00=zeros(6,7362497,"single"); %dE00 refers to a numerical value of color difference
% lab_NF contains six CIELAB color values (L*, a* and b*) while labDB is a
% database of 7362497 CIELAB color values.
for nClrs=1:7362497
dE00(1:6,nClrs)=deltaE2000(lab_NF(1:6,1:3),labDB(nClrs,1:3));
end
Thanks in advance!
  17 comentarios
Bruno Luong
Bruno Luong el 17 de Nov. de 2022
Editada: Bruno Luong el 17 de Nov. de 2022
I run gain the code on my Intel laptop
R2021a: 85 seconds
R2022b: 87 seconds
Aiman Raza
Aiman Raza el 17 de Nov. de 2022
So it clearly is my machine which is just not great. I will try to rewrite the code more smartly to improve the processing duration. Thanks a lot.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 17 de Nov. de 2022
n = 32000; % 7362497;
dE00 = zeros(6, n,"single");
lab_NF = rand(6, 3, 'single');
labDB = rand(n, 3, 'single');
tic
for nClrs = 1:n
dE00(1:6, nClrs) = deltaE2000(lab_NF(1:6, 1:3), labDB(nClrs, 1:3));
end
toc
Elapsed time is 1.013390 seconds.
% Faster without explicit indexing:
tic
for nClrs = 1:n
dE00(:, nClrs) = deltaE2000(lab_NF, labDB(nClrs, :));
end
toc
Elapsed time is 0.722065 seconds.
  1 comentario
Aiman Raza
Aiman Raza el 17 de Nov. de 2022
Editada: Aiman Raza el 17 de Nov. de 2022
Thanks a lot! Removing the indexing did reduce the time to 106s. It is still better than before. I will try to code without a loop. That might further improve the timing.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by