MATLAB COMPILER RELEASE NOTES User's Guide Page 173

  • Download
  • Add to my manuals
  • Print
  • Page
    / 264
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 172
Optimizing Arrays
6-5
Optimizing Arrays
Scalar Arrays
(fold_scalar_mxarrays) When this optimization is enabled, all constant,
scalar-valued array operations are folded at compile time and are stored in a
constant pool that is created once at program initialization time. Folding
reduces the number of computations that are performed at runtime, thus
improving runtime performance.
Scalar folding can dramatically improv e the performance of code that is
manipulating scalar arrays, but it makes the code less readable. For e xample,
function y = foo(x)
y = 2*pi*x;
If you compile this with the -O none option, you get
...
mlfAssign(&y, mclMtimes(mlfScalar(6.283185307179586),
mclVa(x, "x")));
...
Compiling with -O none -O fold_scalar_mxarrays:on,gives
...
mlfAssign(&y, mclMtimes(_mxarray0_, mclVa(x, "x")));
...
In the optimized case, this code uses _mxarray0_, which is initialized at
program start-up to hold the correct value. All constants with the s ame value
use the same
mxArray variable in the constant pool.
Nonscalar Arrays
(fold_non_scalar_mxarrays) This optimization is very similar to
fold_scalar_mxarrays. It folds nonscalar mxArray values into compile-time
arrays that are initialized at program start-up. This can have a large
performance impact if you are constructing arrays that use
[] or {} within a
loop. This optimization makes the code less readable. For example,
function y = test
y = [ 1 0; 0 1] * [ pi pi/2; -pi -pi/2 ];
Page view 172
1 2 ... 168 169 170 171 172 173 174 175 176 177 178 ... 263 264

Comments to this Manuals

No comments