0
0
Embedded Cprogramming~5 mins

Why serial communication is needed in Embedded C - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why serial communication is needed
O(n)
Understanding Time Complexity

We want to understand how the time cost grows when using serial communication in embedded systems.

How does sending data one bit at a time affect the speed as data size grows?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


void sendDataSerial(const char* data, int length) {
    for (int i = 0; i < length; i++) {
        sendByte(data[i]);  // send one byte at a time
    }
}

void sendByte(char byte) {
    // code to send one byte serially
}
    

This code sends data one byte at a time over a serial connection.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Sending each byte one by one in a loop.
  • How many times: The loop runs once for every byte in the data.
How Execution Grows With Input

As the amount of data grows, the time to send it grows in a straight line.

Input Size (n)Approx. Operations
1010 sendByte calls
100100 sendByte calls
10001000 sendByte calls

Pattern observation: Doubling the data doubles the time needed.

Final Time Complexity

Time Complexity: O(n)

This means the time to send data grows directly with the amount of data.

Common Mistake

[X] Wrong: "Sending data serially is instant regardless of size."

[OK] Correct: Each byte takes time to send, so more data means more time.

Interview Connect

Understanding how data size affects sending time helps you explain real embedded system behavior clearly.

Self-Check

"What if we sent data in parallel instead of one byte at a time? How would the time complexity change?"