Performance-related coding guidelines
summary
Benchmarks on a dedicated machine (each run 7 times) compare vector vs list vs deque across push_back, random insert/remove, linear search and sort for 1 byte and 4 KB element sizes. Results: vector wins for small elements due to cache locality, list performs worst for 1 byte but becomes fastest for 4 KB elements, deque often sits between and can be ~2x faster than vector on front inserts. Using reserve avoids costly realloc + copies, noexcept moves and move constructors cut runtimes (observed ~2–3x speedup), and compile‑time work with constexpr + string_view + std::array removes runtime overhead.
AI-written summary · about
chapters (12)
- 0:00Introduction and motivation
- 1:07Data structure performance comparison
- 5:53Spatial locality and caching
- 12:48Element size impact on performance
- 16:28Should we avoid linked lists?
- 21:10Memory allocation and reserve
- 26:24Vector vs deque vs list summary
- 27:53Transition to non-trivial types
- 31:11Move semantics in containers
- 35:33Compile-time optimizations
- 41:35C++20 constexpr utilities
- 46:35Q&A and closing remarks
