性能
在设计用于代码生成的 MATLAB® 算法时,请遵循以下规范来提高生成代码的性能。
模块
MATLAB Function | 在 Simulink 模型中包含 MATLAB 代码 |
函数
coder.areUnboundedVariableSizedArraysSupported | Check if current configuration settings allow unbounded variable-size arrays (自 R2024a 起) |
coder.inline | 控制生成代码中当前函数的内联 |
coder.inlineCall | Inline called function in generated code (自 R2024a 起) |
coder.nonInlineCall | Prevent inlining of called function in generated code (自 R2024a 起) |
coder.unroll | 通过为每次循环迭代生成循环体的副本来展开 for 循环 |
coder.const | 在生成的代码中将表达式折叠为常量 |
主题
- 展开 for 循环和 parfor 循环
控制循环展开。
- 内联代码
内联通过用函数体替换函数调用消除了函数调用的开销。
- Avoid Data Copies of Function Inputs in Generated Code
Generate code that passes input arguments by reference.
- Generate Reusable Code
To reuse functions, save them in files or integrate external functions into generated code.
- Control Run-Time Checks
Improve performance by disabling run-time checks.
- LAPACK Calls for Linear Algebra in a MATLAB Function Block
LAPACK function calls improve the simulation speed of MATLAB Function block algorithms that call certain linear algebra functions.
- BLAS Calls for Matrix Operations in a MATLAB Function Block
BLAS function calls improve the simulation speed of MATLAB Function block algorithms that call certain low-level vector and matrix functions.
- FFTW calls for fast Fourier transform functions in a MATLAB Function Block
FFTW function calls improve the simulation speed of MATLAB Function block algorithms that call MATLAB fast Fourier transform (FFT) functions.