IEC 60870-5 protocol in SCADA systems - Time & Space Complexity
When working with the IEC 60870-5 protocol in SCADA systems, it's important to understand how processing time changes as the number of messages grows.
We want to know how the system handles more data and how long it takes to process each message.
Analyze the time complexity of the following code snippet.
// Process incoming IEC 60870-5 messages
function processMessages(messages) {
for (let i = 0; i < messages.length; i++) {
let message = messages[i];
if (message.type === 'ASDU') {
decodeASDU(message.data);
}
}
}
function decodeASDU(data) {
// Decode data fields
for (let j = 0; j < data.length; j++) {
parseField(data[j]);
}
}
This code processes a list of IEC 60870-5 messages, decoding each ASDU message by parsing its data fields.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over all messages and, for each ASDU message, loop over its data fields.
- How many times: Outer loop runs once per message (n times), inner loop runs once per data field in each message (m times per message).
As the number of messages increases, and the size of each message's data grows, the total work grows by multiplying these two factors.
| Input Size (messages n) | Data Fields per Message (m) | Approx. Operations |
|---|---|---|
| 10 | 5 | 50 |
| 100 | 5 | 500 |
| 100 | 50 | 5000 |
Pattern observation: The total operations grow by multiplying the number of messages by the number of data fields per message.
Time Complexity: O(n * m)
This means the processing time grows proportionally to both the number of messages and the size of each message's data.
[X] Wrong: "Processing time depends only on the number of messages, not on the data size inside each message."
[OK] Correct: Each message's data fields must be parsed, so larger data means more work per message, increasing total time.
Understanding how nested loops affect processing time helps you explain system performance clearly and shows you can reason about real-world data handling.
What if we changed the code to process only every other message? How would the time complexity change?