Speeding up IF and comparisons whithin a loop

조회 수: 13 (최근 30일)
Vogel
Vogel 2019년 3월 30일
댓글: Vogel 2019년 4월 1일
I have a function which is being run inside a loop.
The line consuming more time is an IF condition. X is not even a vector, just a single value.
if (ge(X, 0.557893) && le(X,1))
....
end
(The condition is equivalent to X>= 0.557893 && X<=1.)
Do you know why? Is there any equivalent and faster way to do it?
IF.PNG

채택된 답변

Jan
Jan 2019년 3월 30일
Do not take the output of the profiler too literally. If this is the first access to the value of X, it might be the time for copying the value from the slow RAM to the fast processor cache. Only if you consider the surrounding code, the meaning of the profiled times become more or less meaningful.
The general idea would be to vectorized the code, I guess.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by