|GNU Octave Manual Version 3|
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
RRP £24.95 ($39.95)
33.8 Tips for Making Code Run Faster.
Here are some ways of improving the execution speed of Octave programs.
- Avoid looping wherever possible.
- Use iteration rather than recursion whenever possible. Function calls are slow in Octave.
Avoid resizing matrices unnecessarily. When building a single result
matrix from a series of calculations, set the size of the result matrix
first, then insert values into it. Write
result = zeros (big_n, big_m) for i = over:and_over r1 = ... r2 = ... result (r1, r2) = new_value (); endforinstead of
result = ; for i = ever:and_ever result = [ result, new_value() ]; endfor
fevalwhenever possible, because they require Octave to parse input or look up the name of a function in the symbol table. If you are using
evalas an exception handling mechanism and not because you need to execute some arbitrary text, use the
trystatement instead. See section 10.9 The
If you are calling lots of functions but none of them will need to
change during your run, set the variable
"all"so that Octave doesn't waste a lot of time checking to see if you have updated your function files.
|ISBN 095461206X||GNU Octave Manual Version 3||See the print edition|