Why data logging matters in Arduino - Performance Analysis
When we log data on an Arduino, we want to know how long it takes as we collect more data points.
We ask: How does the time to log data grow as we record more entries?
Analyze the time complexity of the following code snippet.
void logData(int data[], int size) {
for (int i = 0; i < size; i++) {
Serial.println(data[i]);
}
}
This code sends each data point from an array to the serial monitor one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through the data array to print each item.
- How many times: Exactly once for each data point in the array.
Explain the growth pattern intuitively.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 print commands |
| 100 | 100 print commands |
| 1000 | 1000 print commands |
Pattern observation: The number of operations grows directly with the number of data points.
Time Complexity: O(n)
This means the time to log data grows in a straight line as you add more data points.
[X] Wrong: "Logging a few more data points won't affect the time much."
[OK] Correct: Each extra data point adds more work, so time increases steadily, not stays the same.
Understanding how data logging time grows helps you write efficient code for real devices that collect lots of information.
"What if we buffered data and sent it all at once? How would the time complexity change?"