This guide will help you speed up your simulations and improve the performance of your Simulink® model(s). The steps below point you to some tools that you can use, based on your situation, for fixing or analyzing the performance of your model(s). Please contact Technical Support if you have any issues performing these steps or if you can’t resolve your issue. The steps ask you to collect the data as you move through them. This data will help Technical Support understand your problem faster on the off chance that you need additional support.
Step 1: Consider Recent Changes
Did changing your model or MATLAB release cause a performance issue?
Model Comparison
If you modified your model as part of the process of upgrading to a new MATLAB® release, compare the model to its original version to scan for changes that might negatively affect performance.
Once the comparison is done, click Publish and save the report.
Upgrade Advisor
If you upgraded to a new version and didn’t identify problems with the Comparison Tool, run the Upgrade Advisor. The Upgrade Advisor can identify cases where you can benefit by changing your model to use new features and settings in Simulink.
Once the Upgrade Advisor has finished running the checks, save the report.
Model Comparison
If you significantly modified your model and are not sure what caused it to slow down, compare the model to its original version to scan for changes that have negatively affected performance.
Once the comparison is done, click Publish and save the report.
Step 2: Run the Performance Advisor
The Performance Advisor analyzes the model for configuration settings and modeling patterns that can slow down simulation and suggests actions to improve performance. After making modifications to the model, the Performance Advisor can do a final validation to show the improvements made.
Once the Advisor has done the final validation, save the report.
If you want to try additional techniques to improve performance, proceed to Step 3.
Step 3: Initialization Profiling
Do you have a SimulationOutput
object with results from a recent simulation?
Check the time required to initialize the model using this command, replacing out
with the name of your SimulationOutput
object if necessary.
out.SimulationMetadata.TimingInfo.InitializationElapsedWallTime
If the initialization time is larger than you expect and you want to investigate further, continue to the next part in Step 3. If you prefer to focus on potential simulation problems, proceed to Step 4.
Check the time required to initialize the model using this command, replacing out
with the name of your SimulationOutput
object if necessary.
out.SimulationMetadata.TimingInfo.InitializationElapsedWallTime
Replace out
with the name of your SimulationOutput
object if necessary.
If the initialization time is larger than you expect and you want to investigate further, continue to the next part in Step 3. If you prefer to focus on potential simulation problems, proceed to Step 4.
In most cases, when you run a Simulink simulation, an object containing information about the simulation is created.
To generate a SimulationOutput
object for your model, run these commands, replacing MyModel
with the name of your model.
mdl = "MyModel";
out = sim(mdl,StopTime=“0”,CaptureErrors=“on”);
These commands initialize the model and stop the simulation at time 0. The SimulationOutput
object generated from the simulation includes information about the initialization time.
Once you have out
available, check the time required to initialize the model using this command:
out.SimulationMetadata.TimingInfo.InitializationElapsedWallTime
If the initialization time is larger than you expect and you want to investigate further, continue to the next part in Step 3. If you prefer to focus on potential simulation problems, proceed to Step 4.
In most cases, when you run a Simulink simulation, an object containing information about the simulation is created. Before attempting to get a new one, check your base workspace for any existing object with a value of “1x1 SimulationOutput
” in the base workspace.
To generate a SimulationOutput
object for your model, run these commands, replacing MyModel
with the name of your model.
mdl = "MyModel";
out = sim(mdl,StopTime=“0”,CaptureErrors=“on”);
These commands initialize the model and stop the simulation at time 0. The SimulationOutput
object generated from the simulation includes information about the initialization time.
Once you have out
available, check the time required to initialize the model using this command:
out.SimulationMetadata.TimingInfo.InitializationElapsedWallTime
If the initialization time is larger than you expect and you want to investigate further, continue to the next part in Step 3. If you prefer to focus on potential simulation problems, proceed to Step 4.
Use the MATLAB Profiler to look for code that may be slowing down initialization.
MATLAB Profiler
Sometimes, there are model callbacks or initialization scripts that have a large MATLAB code base. The MATLAB Profiler analyzes the time it takes to execute the MATLAB code associated with your model to help you identify potential bottlenecks.
Run these commands in the Command Window before running the simulation:
profile clear; profile on;
After the simulation is complete, run this command:
p = profile('info');
After the MATLAB Profiler runs, click on Print and save the report as a PDF.
Look at the results of profiler. If there are functions or scripts that you did not expect, or if the execution of some MATLAB code is taking longer than you expect, take some time to try to fix it.
If you want to try additional techniques to improve performance, proceed to Step 4.
Step 4: Simulation Profiling
Are you using a variable-step solver?
If you are not sure, look at the Solver pane in the Configuration Parameters dialog box.
Simulink Profiler
The Simulink Profiler analyzes the time needed to execute your model simulation, breaking it down by component. You can use this information to set a baseline and identify potentially problematic constructs in your model. Take note of the models that take a lot of self time.
After the profile is complete, under Share, click on Generate Report and save the report.
If there is a situation with your model that was not addressed in these steps, proceed to Step 5.
Simulink Profiler
Run Simulink Profiler.
The Simulink Profiler analyzes the time needed to execute your model simulation, breaking it down by component. You can use this information to set a baseline and identify potentially problematic constructs in your model. Take note of the models that take a lot of self time.
After the profile is complete, under Share, click on Generate Report and save the report.
Solver Profiler
Run Solver Profiler.
The Solver Profiler analyzes the dynamics of your model and can help you identify when the simulation performance degrades due to smaller time steps or major simulation events (including solver exceptions and solver resets).
After the profiling is done, save the graph by clicking on Export Tab and then save as a .fig file.
If there is a situation with your model that was not addressed in these steps, proceed to Step 5.
Step 5: Further Steps
Are you satisfied with the performance of your model?
Thank you for using the Simulink Performance Guide!
Check out these additional resources that explore performance-improving techniques to keep your model running like a well-oiled machine:
Thank you for the time invested in debugging and collecting diagnostic information.
Please contact Support and provide the reports generated during this process.