Search⌘ K
AI Features

Some Performance Considerations

Explore the performance implications of choosing and using C++ standard library containers. Understand how container overhead affects small datasets versus large ones and why cache-friendly structures like std::vector often perform better. Learn to use efficient API functions such as contains() and empty() to express intent clearly and improve runtime performance. This lesson helps you make informed container choices and apply best practices for optimizing container operations.

Performance considerations

We have now covered the three major container categories:

  1. Sequence containers

  2. Associative containers

  3. Container adaptors

This lesson will provide us with some general performance advice to consider when working with containers.

Balancing between complexity guarantees and overhead

Knowing the time and memory complexity of data structures is important when choosing between containers. But it's equally important to remember that each container is afflicted with an overhead cost, which has a bigger impact on the performance of smaller datasets. The complexity guarantees only become interesting for sufficiently large datasets. It's up to us, though, to decide what sufficiently large means in our use cases. Here, again, we need to measure our program while executing it to gain insights.

In addition, the fact that computers are equipped with memory ...