| MATLAB Compiler | ![]() |
(optimize_integer_for_loops) This optimization detects when a loop starts and increments with integers and replaces the loop with a much simpler loop that uses C integer variables instead of array valued variables. The performance improvements with this optimization can be dramatic.
| Note This optimization causes the variable names in the resulting C program to differ from those in the M-file. Therefore, it is recommended that you do not use this option when debugging. |
function test(x)
for i = 1:length(x)-1
x(i) = x(i) + x(i+1)
end
If you compile this with the -O none option, you get
...
{
mclForLoopIterator viter__;
for (mclForStart(
&viter__,
mlfScalar(1),
mclMinus(mclVe(mlfLength(mclVa(x, "x"))),
mlfScalar(1)), NULL);
mclForNext(&viter__, &i);
) {
...
}
mclDestroyForLoopIterator(viter__);
}
...
Compiling with -O none -O optimize_integer_for_loops:on gives
...
{
int v_ = mclForIntStart(1);
int e_ = mclForIntEnd(mlfScalar(mclLengthInt(mclVa(x, "x"))
- 1));
if (v_ > e_) {
mlfAssign(&i, _mxarray0_);
} else {
...
for (; ; ) {
...
if (v_ == e_) {
break;
}
++v_;
}
mlfAssign(&i, mlfScalar(v_));
}
...
| Optimizing Loops | Optimizing Conditionals | ![]() |