Task notification vs queue performance in FreeRTOS - Performance Comparison
When working with FreeRTOS, it's important to know how fast different communication methods work between tasks.
We want to see how the time to send and receive messages grows as more messages are handled.
Analyze the time complexity of sending and receiving messages using task notifications and queues.
// Using task notification
xTaskNotifyGive(taskHandle);
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
// Using queue
xQueueSend(queueHandle, &data, portMAX_DELAY);
xQueueReceive(queueHandle, &data, portMAX_DELAY);
This code shows sending and receiving a message using task notifications and queues in FreeRTOS.
Look at what repeats when sending many messages.
- Primary operation: Sending and receiving messages repeatedly.
- How many times: Once per message, repeated for all messages.
As the number of messages grows, the time to send and receive grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 sends + 10 receives |
| 100 | 100 sends + 100 receives |
| 1000 | 1000 sends + 1000 receives |
Pattern observation: The total operations grow directly with the number of messages.
Time Complexity: O(n)
This means the time to send and receive messages grows linearly with the number of messages.
[X] Wrong: "Task notifications and queues have the same speed regardless of message count."
[OK] Correct: Task notifications are simpler and faster for single messages, but queues handle multiple messages with more overhead, so performance differs as message count grows.
Understanding how different FreeRTOS communication methods scale helps you choose the right tool and explain your choices clearly in real projects.
What if we changed from a single-item queue to a multi-item queue? How would the time complexity change?