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

4 次查看(过去 30 天)
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 个评论
Bruno Luong
Bruno Luong 2022-11-17
编辑:Bruno Luong 2022-11-17
I run gain the code on my Intel laptop
R2021a: 85 seconds
R2022b: 87 seconds
Aiman Raza
Aiman Raza 2022-11-17
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2022-11-17
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 个评论
Aiman Raza
Aiman Raza 2022-11-17
编辑:Aiman Raza 2022-11-17
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by