MATLAB Compiler | ![]() ![]() |
(optimize_integer_for_loops
) This optimization detects when a loop starts and increments with integers. It 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, we recommend that you do not use this option when debugging. |
If you compile this with the -O none
option, you get
... { mclForLoopIterator viter__; for (mclForStart( &viter__, mlfScalar(1), mclMinus(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_ = 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 | ![]() |