Speeding up IF and comparisons whithin a loop
조회 수: 13 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!