Main Content

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, such as charts with signal logging, do not qualify for JIT mode.

Stateflow models include debugging support for simulation. To gain optimal performance, turn off debugging by using this command:

sfc("coder_options",forceDebugOff=true);

When you run this command, your Stateflow charts do not have debugging support or run-time error checking.

Note

When you turn off debugging, animation is also turned off.

Disable Simulation Target Parameters That Impact Execution Speed

To simulate your model more quickly, open the Configuration Parameters dialog box and, in the Simulation Target pane, under Advanced parameters, 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. See Echo expressions without semicolons (Simulink).

  • Break on Ctrl+C — To disable ability to break out of long-running execution using Ctrl+C, clear this check box. See Break on Ctrl+C (Simulink).

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 Closed

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.

Related Topics