Performance: Difference between revisions

61 bytes added ,  22 May 2012
highlighting
(Adding syntax highlight)
(highlighting)
Line 35: Line 35:
When passing variables to a function, Octave will only make a copy of it is going to be modified. That is, unless the argument needs to be changed, the variable will be like a reference and take no extra memory or time to write.
When passing variables to a function, Octave will only make a copy of it is going to be modified. That is, unless the argument needs to be changed, the variable will be like a reference and take no extra memory or time to write.


{{Code|Looking at lazy copying|<pre>
{{Code|Looking at lazy copying|<syntaxhighlight lang="matlab" style="font-size:13px">
function read_arg (arg)
function read_arg (arg)
   x = arg(1);
   x = arg(1);
Line 52: Line 52:
t = cputime (); modi_arg (a); t_read = cputime () -t  ## takes some time since a copy of a will be made to be modified
t = cputime (); modi_arg (a); t_read = cputime () -t  ## takes some time since a copy of a will be made to be modified
t = cputime (); chan_arg (a); t_read = cputime () -t  ## takes NO time since even though arg is modifed, it's not based on the original value
t = cputime (); chan_arg (a); t_read = cputime () -t  ## takes NO time since even though arg is modifed, it's not based on the original value
</pre>}}
</syntaxhighlight>}}


=== Global variables ===
=== Global variables ===
657

edits