Main Content

比较性能

模拟模式的性能

当仿真执行时间超过代码生成所需的时间时,加速器和快速加速器模式与正常模式相比,可提供最佳的速度。因此,当模拟执行时间为几分钟或更长时间时,加速器和快速加速器模式通常比正常模式更好。但是,具有大量状态流的模型®or MATLAB Function blocks might show only a small speed improvement over Normal mode because in Normal mode these blocks also simulate through code generation.

Including tunable parameters in your model can also increase the simulation time.

该图以一般术语显示了在正常,加速器和快速加速器模式中模拟的假设模型的性能。

Performance When the Target Must Be Rebuilt

图中的实线显示必须重建目标代码时性能(“所有目标过期”)。对于这个假设的模型,时间尺度在几分钟的顺序上,但对于更复杂的模型可能会更长。

如图中的概括,以正常模式编译模型所需的时间小于构建加速器目标或快速加速器可执行器所需的时间。从数字中可以明显看出,对于小模拟停止时间,正常模式会导致比加速器模式或快速加速器模式更快的总体模拟时间。

The crossover point where Accelerator mode or Rapid Accelerator mode result in faster execution times depends on the complexity and content of your model. For instance, those models running in Accelerator mode containing large numbers of blocks using interpreted code (seeSelect Blocks for Accelerator Mode)除非模拟停止时间非常大,否则在正常模式下的运行速度可能不会快得多。同样,除非模拟停止时间长,否则具有大量状态流图块或MATLAB功能块的模型可能不会在正常模式下显示出太大的提高。您可以通过代码生成加速使用状态流图表块或MATLAB功能块。

出于说明目的,该图形表示具有大量状态流图块或MATLAB功能块的模型。如果模型不包含这些块,则标有“正常”的曲线的初始时间要小得多。

目标最新时的性能

As shown by the broken lines in the figure (“all targets up to date”) the time for the Simulink®software to determine if the Accelerator target or the Rapid Accelerator executable are up to date is significantly less than the time required to generate code (“all targets out of date”). You can take advantage of this characteristic when you wish to test various design tradeoffs.

例如,您可以一次生成ACCELERATOR模式目标代码,并使用它使用一系列增益设置来模拟模型。这是使用加速器或快速加速器模式的一种特别有效的方法,因为这种类型的更改不会导致目标代码重新生成。这意味着目标代码是在模型首次运行时生成的,但是在后续运行时,Simulink代码仅花费时间来验证目标是否最新。金宝app此过程比生成代码要快得多,因此随后的运行速度可以比初始运行快得多。

因为检查目标比代码生成要快,所以当目标最新时,交叉点比必须生成代码时小。这意味着与正常模式相比,即使在短时间内,随后的模型运行可能会更快地模拟加速器或快速加速器模式。

Measure Performance

您可以使用抽动,,,,TOC,,,,andsimcommands to compare Accelerator mode or Rapid Accelerator mode execution times to Normal mode.

  1. 打开您的模型。

  2. Simulation标签,在模拟部分中,选择普通的从下拉菜单。

  3. 使用抽动,,,,TOC,,,,andsimcommands at the command line prompt to measure how long the model takes to simulate in Normal mode:

    抽动,,,,[t,x,y]=sim('myModel',10000);toc

    抽动andTOC一起工作以记录并返回经过的时间并显示以下消息:

    经过的时间为17.789364秒。

  4. Simulation标签,在模拟部分中,选择AcceleratororRapid Accelerator从下拉菜单。Build an executable for the model by clicking。的acceleration modes use this executable in subsequent simulations as long as the model remains structurally unchanged.加速模型中的代码再生讨论导致您的模型重建的事物。

  5. 在命令提示符下重新运行编译模型:

    抽动,,,,[t,x,y]=sim('myModel',10000);toc

  6. 显示的经过的时间显示了加速模型的运行时间。例如:

    Elapsed time is 12.419914 seconds.

The difference in elapsed times (5.369450 seconds in this example) shows the improvement obtained by accelerating your model.

相关示例

更多关于