which one is faster? defining a variable as a global variable or as an input of function?
古いコメントを表示
I want to know which one is faster? defining a variable as a global variable or as an input of function?
採用された回答
その他の回答 (1 件)
David Young
2015 年 8 月 23 日
編集済み: David Young
2015 年 8 月 23 日
2 投票
It is usually a bad idea to use global variables. There are many papers, going back over 40 years or more, explaining why. One example is this chapter. I strongly recommend you avoid them. (Global variables, that is, not the papers.)
It is very unlikely that using a global rather than passing an argument will make a noticeable difference to your execution time. If you really suspect it might, the best way to find out is to do some tests using timeit.
カテゴリ
ヘルプ センター および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!