필터 지우기
필터 지우기

Is it faster to use array size as an input or calculate size

조회 수: 1 (최근 30일)
Josh
Josh 2015년 4월 10일
편집: James Tursa 2015년 4월 10일
I have a function which will be called many times and performs operations on an array. The function is dependent on the size of the array. Is it faster to calculate the size before implementing the function, or just use the size command as the first step of the function? Thanks

답변 (1개)

James Tursa
James Tursa 2015년 4월 10일
편집: James Tursa 2015년 4월 10일
For ease of use, typically the size would be generated inside the function to make sure there was no mismatch. For speed, this choice is likely in the noise and may not matter where you do it. How simple is your function? Does the array argument change size during the execution of the program? Etc. If you are concerned about speed then use the profiler to determine where to concentrate your efforts. It is probably not with that line.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by