Is it faster to use array size as an input or calculate size
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!