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!