0
0
Arduinoprogramming~5 mins

Why data logging matters in Arduino - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why data logging matters
O(n)
Understanding Time Complexity

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?

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

Explain the growth pattern intuitively.

Input Size (n)Approx. Operations
1010 print commands
100100 print commands
10001000 print commands

Pattern observation: The number of operations grows directly with the number of data points.

Final Time Complexity

Time Complexity: O(n)

This means the time to log data grows in a straight line as you add more data points.

Common Mistake

[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.

Interview Connect

Understanding how data logging time grows helps you write efficient code for real devices that collect lots of information.

Self-Check

"What if we buffered data and sent it all at once? How would the time complexity change?"