Executes a specified number of loops and prints out both the total execution time and the average execution time of each loop.
- Warning
- This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.
The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
📜 Loop Timing Sample App
A sample application that measures the execution time of the specified number of loops.
5 double MAX_LOOPS = 10000;
6 double timestamp = now();
7 int32 fastestLoopIndex;
8 int32 slowestLoopIndex;
9 double previousTime = 0;
10 double currentTime = 0;
12 double averageTime = 0;
13 double currentDelta = 0;
14 double minDelta = 100000000;
15 double maxDelta = 0.0;
18 for(i = 0 ; i < MAX_LOOPS; ++i)
21 currentDelta = currentTime - previousTime;
23 if(currentDelta < minDelta)
25 minDelta = currentDelta;
28 if(currentDelta > maxDelta)
30 maxDelta = currentDelta;
34 previousTime = currentTime;
35 totalTime += currentDelta;
38 print(
"Fastest loop is " + minDelta +
" ms on loop index " + fastestLoopIndex +
".");
39 print(
"Slowest loop is " + maxDelta +
" ms on loop index " + slowestLoopIndex +
".");
40 averageTime = totalTime / MAX_LOOPS;
41 print(
"Total time is " + totalTime +
" ms for " + MAX_LOOPS +
" loops. Average loop time is " + averageTime +
" ms.");
Learn more in topic page.