Table of Contents
Computation Time
Outputs the computation time of a Function Call Subsystem or task, measured using a high-resolution independent time source.
Library
MATLAB Command Line
Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:
qc_open_library('quarc_library/Sources/Time')Description
When the Measure CPU time option is not checked, then the Computation Time block executes the attached Function Call Subsystem and measures the time it takes to execute using a high-resolution independent time source. On some targets, such as the Windows target, this time has nanosecond resolution. The measured computation time is output by the block.
When the Measure CPU time option is checked then the Computation Time block executes the attached Function Call Subsystem and measures the CPU time it takes to execute. CPU time measurements generally have less resolution than the high-resolution time source but reflect actual CPU time used rather than wall clock time. Both kernel mode and user mode CPU time are included.
In many cases, the blocks to be measured include a discrete-time block with a sample time. Normally, all blocks within a Function Call Subsystem must inherit their sample time. However, it is possible to tell Simulink that the Function Call Subsystem will be called periodically so that discrete-time blocks may be used within the Function Call Subsystem. Open the Function Call Subsystem and double-click on the Trigger block inside the subsystem. The Trigger block is depicted below.
In the block parameters for the Trigger block, change
the Sample time type from triggered
to
periodic
. Then, in the Sample time field,
enter the sample time of the Computation Time block driving the
Function Call Subsystem. Typical settings are shown below.
For continuous-time blocks, it may be necessary to replace them with the equivalent discrete-time blocks. The blockset in the QUARC Targets/Discrete library are very convenient for replacing continuous-time blocks with their discrete equivalent because the blocks look just like the continuous-time counterparts, taking the continuous-time parameters, but convert to discrete-time internally.
For best results, put a For Iterator Subsystem inside
the Function Call Subsystem and measure the time
to execute the desired blocks N
times. Divide the computation time
by N
to get the time to execute the desired blocks once. This scheme
amortizes the cost of cache flushing, DMA and measuring time itself over N
iterations, since
the Computation Time block does not compensate for these factors. Do not forget to slow down the sample time of the model to account
for the time required to execute the For Iterator Subsystem.
The Computation Time block can also measure the computation time of the task itself, rather than a Function Call Subsystem. Simply check the Output computation time of task option. The function call output will disappear and the block will output the computation time for the task associated with the sample time of the block.
Limitations
Windows CPU Time
On Windows, CPU time measurement is rather crude, with only a 15 millisecond resolution. Hence, the computation time may appear as zero with the occasional 15 millisecond spikes, when the computation time is small.
Input Ports
This block has no input ports.
Output Ports
f()
The control signal to connect to the Function Call Subsystem that the block is to execute. This output is not present when the computation time of the model is being measured.
Tc
The computation time for the Function Call Subsystem or model, in seconds.
Parameters and Dialog Box
Sample time
The sample time of the block. A sample time of 0 indicates that the block will be treated as a continuous time block. A positive sample time indicates that the block is a discrete time block with the given sample time.
A sample time of -1 indicates that the block inherits its sample time. Since this is a source block, only inherent the sample time when it is placed in a conditionally executed subsystem, like a Triggered Subsystem, Enabled Subsystem, Function Call Subsystem or in a referenced model.
To use the fundamental sampling time of the model, set the sample time to qc_get_step_size, which is a QUARC function that returns the fundamental sampling time of the model.
The default sample time is set to qc_get_step_size.
Output computation time of task
Check this option to output the computation time of the task associated with the sample time of the block, instead of executing a Function Call Subsystem.
The Computation Time block cannot be placed in a referenced model when measuring the computation time of the task. It must be placed in the top-level model in this case. |
Measure CPU time
Check this option to measure CPU time rather than wall block computation time. If the computation time of the model is being measured then this will be the process CPU time. If the computation time of a subsystem is being measured then this will be the thread CPU time.
On Windows, CPU time measurement is rather crude, with only a 15 millisecond resolution. Hence, the computation time may appear as zero with the occasional 15 millisecond spikes, when the computation time is small. |
The Computation Time block cannot be placed in a referenced model when measuring the computation time of the model. It must be placed in the top-level model in this case. |
Targets
Target Name |
Compatible* |
Model Referencing |
Comments |
---|---|---|---|
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
Last fully supported in QUARC 2018. |
|
Rapid Simulation (RSIM) Target |
Yes |
Yes |
|
S-Function Target |
No |
N/A |
Old technology. Use model referencing instead. |
Normal simulation |
Yes |
Yes |
See Also
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.