# 7.5 Why is My Simulation Running So Slowly?

The following are the most common causes of slow simulation speed:

  1. MATLAB Function Block - When a MATLAB Fcn block is present, the MATLAB interpreter is called at each time step. This drastically reduces the simulation speed. Use the built-in Fcn block whenever possible.

  2. S-functions written as M-files - S-functions are evaluated at every time step. By converting the M-file to a MEX-file, performance can be greatly improved. Also, whenever possible, use the built-in blocks to model the S-functions.

  3. Small step sizes or sample times (or a mixture of sample times that are not multiples of each other). It is important to keep the step size small enough to capture important events during the simulation. Conversely, too small a step size will produce more output points than necessary and slow down the simulation.

  4. Any masked blocks in the Extras library that incorporate one of the three above (i.e., graph scopes, autoscaling scopes, spectrum analyzers, etc). Unmask the blocks to see if they call an S-function.

  5. Built in-scope blocks, although their effect is most likely very small.

  6. Algebraic loops - The solutions to algebraic loops are iterative and performed at every time step. Therefore, they severely degrade speed.

  7. Do not feed a White Noise block into an Integrator. For continuous systems use the band-limited white noised block in the Extras/Sources library.

Otherwise, simulation speed is governed by the system (i.e., processor, RAM, amount of swapping that is occurring, etc.). If the above tips do not help, please contact us. We will need to take a closer look at your model and all supporting data and M-files.

(c) Copyright 1994 by The MathWorks, Inc.