Are Global Variables Transferred Significantly Slower Than Function Inputs?
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John Chilleri
le 22 Jan 2017
Réponse apportée : Walter Roberson
le 22 Jan 2017
Hello,
I have a few massive matrices which are used in a function that is called many thousands of times. Due to the way the function is accessed, these massive matrices are brought into the function as globals rather than inputs. If I run the computations within the function thousands of times (having loaded in the matrices once prior to the computations), it's extremely quick. However, when the full code is run, in which the matrices are brought in as globals every call, it's extremely slow.
I've come to the conclusion that it is indeed the global declaration that is slowing things down.
My question(s):
Would passing these massive matrices in as function inputs rather than globals be significantly faster (it's complicated enough to alter that I'd rather ask first)? Or, is there a way to reduce the time it takes for the global declaration to "run"?
I apologize if my question is unclear, I'll gladly provide additional information if needed.
0 commentaires
Réponse acceptée
Walter Roberson
le 22 Jan 2017
Yes, see http://www.mathworks.com/matlabcentral/answers/99537-which-type-of-function-call-provides-better-performance-in-matlab (though I am not sure it is still the case that optimization is turned off for functions that use globals.)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur NaNs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!