Question: n this lab you will run two different performance programs on the Arduino to measure metrics. All code can be found in Moodle. Part I:
n this lab you will run two different performance programs on the Arduino to measure metrics. All
code can be found in Moodle.
Part I: Below is a simple Arduino program that demonstrates performance metrics by measuring the
time it takes to execute a loop for a certain number of iterations:
Arduino Code:
const int numIterations ; Number of iterations for the loop
void setup
Serial.begin; Initialize serial communication
void loop
unsigned long startTime micros; Record the start time in microseconds
Perform a loop for a certain number of iterations
for int i ; i numIterations; i
Perform some dummy computation
int result i ;
unsigned long endTime micros; Record the end time in microseconds
unsigned long elapsedTime endTime startTime; Calculate the elapsed time
Print the performance metrics
Serial.printElapsed Time microseconds: ;
Serial.printlnelapsedTime;
Serial.printAverage Time per Iteration microseconds: ;
Serial.printlnfloatelapsedTime numIterations;
Wait for some time before repeating the loop
delay; second delay
This program measures the time it takes to execute a loop for a certain number of iterations
numIterations Inside the loop, a dummy computation is performed to simulate workload. The elapsed
time for the loop execution and the average time per iteration are then calculated and printed over the
serial port.
To run this program, you'll need an Arduino board and the Arduino IDE. Upload the code to your Arduino
board and open the Serial Monitor in the Arduino IDE to view the performance metrics. Adjust
numIterations as needed to observe different execution times. Keep in mind that this is a simple
demonstration and may not accurately represent realworld performance metrics on more complex
systems.
Using your Arduino, run this program and record your results for at least different iteration values and
record your results.
Answer the following questions related to this program:
How does increasing the value of 'nulterations' affect the elapsed time for excuting the loop, and why?
Explain the significance of using micros to measure elapse time in the Arduino program. How does it differ from using 'millis for this purpose?
What factors could lead to variations in the average time per iteration calculated by the program?
How might you mitigate these factors to obtain more consistent results?
Suggest modifications to the Arduino program to measure te time taken to execute different sections
of code within the loop, rather than the entire loop itself. How would you interpret and analyze the
performance metrics obtained from these modifications?
Discuss potential limitations of using a simple dummy computation within the loop to simulate
workload. How might you enhance the program to better reflect realworld performance scenarios, especially in terms of memory access and IO operation?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
