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 =10000; // Number of iterations for the loop
void setup(){
Serial.begin(9600); // 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 =0; i < numIterations; i++){
// Perform some dummy computation
int result = i *2;
}
unsigned long endTime = micros(); // Record the end time in microseconds
unsigned long elapsedTime = endTime - startTime; // Calculate the elapsed time
// Print the performance metrics
Serial.print("Elapsed Time (microseconds): ");
Serial.println(elapsedTime);
Serial.print("Average Time per Iteration (microseconds): ");
Serial.println((float)elapsedTime / numIterations);
// Wait for some time before repeating the loop
delay(1000); //1 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 real-world performance metrics on more complex
systems.
Using your Arduino, run this program and record your results for at least 3 different iteration values and
record your results.
Answer the following questions related to this program:
1. How does increasing the value of 'nulterations' affect the elapsed time for excuting the loop, and why?
2. Explain the significance of using `micros()` to measure elapse time in the Arduino program. How does it differ from using 'millis()' for this purpose?
3. 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?
4. 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?
5. Discuss potential limitations of using a simple dummy computation within the loop to simulate
workload. How might you enhance the program to better reflect real-world performance scenarios, especially in terms of memory access and I/O operation?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!