comparison doc/interpreter/tips.txi @ 10812:5b68000faac1

tips update
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 21 Jul 2010 09:01:06 +0200
parents 3140cb7a05a1
children 322f43e0e170
comparison
equal deleted inserted replaced
10811:e38c071bbc41 10812:5b68000faac1
107 @item 107 @item
108 Use built-in and library functions if possible. Built-in and compiled functions are very fast. 108 Use built-in and library functions if possible. Built-in and compiled functions are very fast.
109 Even with a m-file library function, chances are good that it is already optimized, or will be 109 Even with a m-file library function, chances are good that it is already optimized, or will be
110 optimized more in a future release. 110 optimized more in a future release.
111 111
112 @item 112 For instance, even better than
113 Avoid computing costly intermediate results multiple times. Octave currently 113
114 @example
115 a = b(2:n) - b(1:n-1);
116 @end example
117
118 is
119
120 @example
121 a = diff (b);
122 @end example
123
124
125 @item
126 Avoid computing costly intermediate results multiple times. Octave currently
114 does not eliminate common subexpressions. 127 does not eliminate common subexpressions.
115 Also, certain internal computation results are cached for variables. 128 Also, certain internal computation results are cached for variables.
116 For instance, if a matrix variable is used multiple times as an index, 129 For instance, if a matrix variable is used multiple times as an index,
117 checking the indices (and internal conversion to integers) is only done once. 130 checking the indices (and internal conversion to integers) is only done once.
118 131
236 249
237 @item 250 @item
238 Octave includes a number of other functions that can replace common types of loops, 251 Octave includes a number of other functions that can replace common types of loops,
239 including @code{bsxfun}, @code{arrayfun}, @code{structfun}, @code{accumarray}. 252 including @code{bsxfun}, @code{arrayfun}, @code{structfun}, @code{accumarray}.
240 These functions can take an arbitrary function as a handle. 253 These functions can take an arbitrary function as a handle.
254 Be sure to get familiar with them if you want to become an Octave expert.
241 255
242 @item 256 @item
243 Avoid calling @code{eval} or @code{feval} excessively, because 257 Avoid calling @code{eval} or @code{feval} excessively, because
244 they require Octave to parse input or look up the name of a function in 258 they require Octave to parse input or look up the name of a function in
245 the symbol table. 259 the symbol table.