Speed Up Simulation
Improve Model Update Performance
Stateflow® uses Just-In-Time (JIT) compilation mode to improve model update performance for most charts in Simulink® models. Stateflow applies JIT mode to charts that qualify. For a chart in JIT mode, Stateflow generates an execution engine in memory for simulation. For these charts, Stateflow does not generate C code or a MEX file to simulate the chart. JIT mode provides the best performance during the compilation of a model.
Some charts do not qualify for JIT mode, such as charts with signal logging.
Stateflow models include debugging support for simulation. To gain optimal performance, turn off debugging by using this command:
sfc('coder_options', 'forceDebugOff', 1);
When you run this command, your Stateflow charts do not have debugging support or run-time error checking.
When you turn off debugging, animation is also turned off.
Disable Simulation Target Options That Impact Execution Speed
To simulate your model more quickly, in the Model Configuration Parameters dialog box, on the Simulation Target pane, clear the check boxes for these parameters:
Echo expressions without semicolons — To disable run-time output in the MATLAB® Command Window, such as actions that do not terminate with a semicolon, clear this check box.
Ensure responsiveness— To disable ability to break out of long-running execution using Ctrl+C, clear this check box.
Speed Up Simulation
Use these tips to further speed up simulation:
Keep Charts Closed
During model simulation, any open charts with animation enabled take longer to simulate. If you keep all charts closed, the simulation runs faster.
Disable Content Preview
During model simulation, any open charts with content preview enabled take longer to simulate. If you disable content preview, the simulation runs faster. To disable content preview, select the chart that has content preview enabled. On the State Chart tab, click Content Preview.
Keep Scope Blocks
During model simulation, any open Scope blocks continuously update their display. If you keep all Scope blocks closed, you can speed up the simulation. After the simulation ends, you can open the Scope blocks to view the results.
Use Library Charts in Your Model
If your model contains multiple charts that do not use JIT mode and contain the same elements, you might generate multiple copies of identical simulation code. By using library charts, you can minimize the number of copies of identical simulation code. For example, using five library charts reduces the number of identical copies from five to one.
For more information, see Create Specialized Chart Libraries for Large-Scale Modeling.