Search⌘ K
AI Features

Associative Containers: Performance Comparison

Explore the performance differences between std::map and std::unordered_map in C++. Understand their access times, ordered versus unordered key/value associations, and see practical tests with a large phone book dataset.

In 95% of our use-cases, we use std::map or std::unordered_map. In fewer cases, we do not need the value associated with the key. Before we begin this lesson and give an overview of numbers to both associative containers, here is one simple rule to remember:

If we want to have a container with ordered key/value associations, use std::map; if not, use a std::unordered_map.

A Phone Book

The eight variations are like different versions of a phone book. What is a phone book? A phone book is a sequence of ...