Main Content

Execution Speed

Improve execution speed of generated C/C++ code

Use code generation options and optimizations to improve the execution speed of the generated code. You can modify or disable dynamic memory allocation, which can affect execution speed. Parallelized code can be generated by using parfor loops. When available, take advantage of preexisting optimized C code and specialized libraries to speed up execution.

For more information about how to optimize your code for specific conditions, see Optimization Strategies.


coder.areUnboundedVariableSizedArraysSupportedCheck if current configuration settings allow unbounded variable-size arrays (Since R2024a)
coder.cevalCall C/C++ function from generated code
coder.constFold expressions into constants in generated code
coder.inlineControl inlining of current function in generated code
coder.inlineCallInline called function in generated code (Since R2024a)
coder.loop.interchangeInterchange loop indices in generated code (Since R2023a)
coder.loop.parallelizeParallelize specific for loops in generated code; disable automatic parallelization (Since R2021a)
coder.loop.reverseReverse loop iteration order in generated code (Since R2023a)
coder.loop.tileTile for-loops in the generated code (Since R2023a)
coder.loop.unrollAndJamUnroll and jam for-loops in the generated code (Since R2023a)
coder.loop.vectorizeVectorize for loops in generated code (Since R2023a)
coder.nonInlineCallPrevent inlining of called function in generated code (Since R2024a)
coder.unrollUnroll for-loop by making a copy of the loop body for each loop iteration
coder.varsizeDeclare variable-size data
parforParallel for-loop


coder.BLASCallbackAbstract class for specifying the BLAS library and CBLAS header and data type information for BLAS calls in generated code
coder.LAPACKCallbackAbstract class for specifying the LAPACK library and LAPACKE header file for LAPACK calls in generated code
coder.fftw.StandaloneFFTW3Interface Abstract class for specifying an FFTW library for FFTW calls in generated code
coder.loop.ControlLoop optimization control object (Since R2023a)


Generated Code Optimizations

memcpy and memset Optimizations

Variable-Size Arrays

Array Layout


Function Calls

Numerical Edge Cases

External Code Integration


Troubleshooting parfor-Loops

Diagnose errors for code generation of parfor-loops.

Resolve Issue: coder.inline("never") and coder.nonInlineCall Do Not Prevent Function Inlining

Troubleshoot instances of coder.inline('never') not preventing inlining.

MEX Generated on macOS Platform Stays Loaded in Memory

Troubleshoot issues that occur when the source MATLAB® code contains global or persistent variables that are reachable from the body of a parfor-loop.