Skip to content

Commit 59f9b93

Browse files
committed
docs: Add remarks on time complexity of algorithms
1 parent 858edf4 commit 59f9b93

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

doc/RealTimeProgramming.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ One can find a few developer checklists for real-time programming such as [this]
1616

1717
- Take care when designing your own code and implementing your own **algorithms**:
1818

19-
- Select algorithms by their **worst-case latency** and not their average latency
20-
- **Split your code** into parts that have to be **real-time** and a **non real-time** part
19+
- Select algorithms by their **worst-case run-time** and not their average run-time (see also [here](https://www.cs.odu.edu/~zeil/cs361/latest/Public/averagecase/index.html)). Keep in mind though that these latency are derived from asymptotic analysis for a large number of elements and only up to a constant (which can be quite large): Two O(n) algorithms might be very different in terms of computational speed (number of instructions and CPU cycles taken), just their scaling will be similar and similarly a O(n²) algorithm might be faster for smaller container sizes. Therefore in particular for smaller or fixed size containers it is necessary to benchmark the chosen algorithm. For small containers the cache locality and memory allocation of an algorithm will be far more important than its asymptotic scaling behavior.
20+
- **Split your code** into parts that have to be **real-time** and a **non real-time** part and make them communicate with lockless programming techniques
2121

2222
- **Set a priority** (nice values) to your real-time code (see [here](https://medium.com/@chetaniam/a-brief-guide-to-priority-and-nice-values-in-the-linux-ecosystem-fb39e49815e0)). `80` is a good starting point. It is not advised to use too high priorities as this might result in problems with kernel threads:
2323

@@ -116,6 +116,8 @@ One can find a few developer checklists for real-time programming such as [this]
116116
117117
- Take care when relying on external libraries to time events and stop times, e.g. [`std::chrono`](https://www.modernescpp.com/index.php/the-three-clocks/).
118118
119-
- Benchmark performance of your code and use tracing library to track you real-time performance. You can always test with simulated load.
119+
- **Benchmark** performance of your code and use tracing library to track you real-time performance. You can always test with simulated load.
120+
121+
- For network applications that require to communicate over a high-speed NIC look into **kernel-bypass** instead of relying on POSIX sockets (see e.g. [here](https://blog.cloudflare.com/kernel-bypass) and [here](https://medium.com/@penberg/on-kernel-bypass-networking-and-programmable-packet-processing-799609b06898))
120122
121123
A good resource for real-time programming is the book ["Building Low Latency Applications with C++"](https://www.packtpub.com/product/building-low-latency-applications-with-c/9781837639359) as well as [this CppCon 2021 talk](https://www.youtube.com/watch?v=Tof5pRedskI). You might also want to have a look at the following two-part guide for audio-developers ([1](https://www.youtube.com/watch?v=Q0vrQFyAdWI) and [2](https://www.youtube.com/watch?v=PoZAo2Vikbo)).

0 commit comments

Comments
 (0)