From: Will on 16 Feb 2010 07:24 Hi, Just a quick question: Does anyone know whether it is faster to pass a variable to a function as an argument or to import global variables within the function body?
From: Cokelid on 16 Feb 2010 07:36 On Feb 16, 7:24 am, "Will " <w.brad...(a)bradford.ac.uk> wrote: > Does anyone know whether it is faster to pass a variable to a function as an argument or to import global variables within the function body? The difference should be negligible, but I would definitely favour passing as an argument as better programming practice. If you subsequently modify the passed-in variable then Matlab will make a copy of the variable local to that function (with the associated overhead), however if it's read-only then it will effectively remain as passed-by-reference and there should be practically no difference.
From: Will on 16 Feb 2010 08:10 Thanks for the response. At the moment the global variables I use are just look-up tables so they are not modified. But I will bear in mind what you have said. Cheers.
|
Pages: 1 Prev: how to measure the Efficiency of code. Next: how to delete a jcombobox |