Are Global Variables Transferred Significantly Slower Than Function Inputs?

13 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de En. de 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.)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by