Benchmark · C++20
SwissMap finds random keys 4.75× faster than std::unordered_map
Three open-addressing hash maps written from scratch (LinearMap, RobinHoodMap and SwissMap), timed against libc++'s std::unordered_map on 64-bit integer keys.
Synthetic keysMedian of 5 interleaved runsApple M5 Pro, one machine
Noisy point. SwissMap's 5 runs here: median 4.31 ns, fastest 3.93 ns, standard deviation 2.22 ns; std::unordered_map: median 20.5 ns, fastest 18.8 ns, standard deviation 1.54 ns. This is one benchmark session, and a rerun gives a different ratio.
Lookups
From 50 % full upward, SwissMap has the fastest lookups on both key patterns
SwissMap compares 8 one-byte tags at once before it reads a key, so a lookup rarely touches more than one key. At 25 % full, LinearMap and RobinHoodMap match or beat it in some cases.
SwissMap's line is lowest from 50 % full upward
Median ns per lookup · 1,048,576 slots · 5 runs per point
Random keys
Sequential keys
Erase-heavy churn
Churn: SwissMap is cheapest on random keys, but std::unordered_map wins on sequential keys
libc++ hashes an integer to itself, so consecutive keys land in consecutive buckets with no collisions. The open-addressing maps scramble keys on purpose, which costs them that free spread. On random keys at 70 % full, an erase plus insert costs 37.7 ns in SwissMap and 230 ns in std::unordered_map.
RobinHoodMap's churn cost roughly doubles between 70 % and 85 % full
Median ns per erase + insert · 5 runs per point
Random keys
Sequential keys
Building a table
Building 4M random keys from empty, SwissMap takes 25.4 ns per insert and std::unordered_map 255 ns
Each run starts from an empty table and includes every resize. std::unordered_map allocates a node for every entry, and its cost per random-key insert climbs from 21.7 ns at 1K keys to 255 ns at 4M. On sequential keys it is the fastest at 4M (18.5 ns against 26.2 ns for SwissMap).
std::unordered_map's insert cost rises with table size on random keys
Median ns per insert, resizes included · 5 runs per point
Random keys
Sequential keys
Per-lookup latency
SwissMap's p99 lookup time is below std::unordered_map's median
The clock ticks every 41 ns, too coarse for a single lookup, so each sample times a batch of 64 lookups and divides by 64 (50,000 batches per table, 70 % full, random keys).
SwissMap's p99 is below every other table's p50
ns per lookup, batch means · 50,000 batches · resolution about 0.6 ns
Batch means. Each sample is the mean of 64 lookups, so a single slow lookup is diluted. The true single-lookup tail is longer than shown.
Methodology
How this was measured
Lookups and churn use a table pre-sized to 1,048,576 slots and filled to a load factor of 25, 50, 70 or 85 %, so load is the only variable. Keys are 64-bit integers, either drawn from a seeded generator (random) or consecutive (sequential). Misses use keys that are guaranteed absent.
Google Benchmark ran every case 5 times in random interleaved order. The page reports the median of those 5 runs. The fastest run and the standard deviation are in every table; the bench code also records the fastest run because it is the least disturbed by other processes.
What this shows
- On random keys at 70 % full, SwissMap's median successful lookup is 4.31 ns against 20.5 ns for std::unordered_map.
- Building 4M random keys takes SwissMap 25.4 ns per insert and std::unordered_map 255 ns.
- On sequential keys, std::unordered_map's identity hash makes it the cheapest table for churn.
What it doesn't show
- Other machines or compilers: one Apple M5 Pro laptop, Apple LLVM, libc++.
- Real key distributions: keys are seeded random or consecutive integers.
- Keys or values other than uint64_t, or memory use.
- Statistical certainty: 5 repetitions in one session; a rerun moves the ratios.
Reproduce
Run it yourself
git clone https://github.com/allenwang0/hashbench.git
cd hashbench
scripts/setup.sh # local venv with pinned CMake and Ninja
source .venv/bin/activate
cmake --workflow --preset release # build and run the tests
scripts/run_bench.sh # benchmarks + this page (about 4 minutes)Environment of the published run · 12 rows
| Field | Value |
|---|---|
| CPU | Apple M5 Pro, 15 logical CPUs |
| OS | Darwin 27.0.0 (arm64) |
| Compiler | Apple LLVM 21.0.0 (clang-2100.4.1.1) |
| Flags | -O3 -DNDEBUG, C++20 |
| Google Benchmark | v1.9.1 |
| Repetitions | 5, interleaved in random order |
| Key seed | 20261110 |
| Table size | 1,048,576 slots for lookups and churn |
| Load average at start | 24.3, 10.1, 6.4 |
| Run date | 2026-11-11 |
| Run commit | 0836fb6e9cc0 |
| Data | results/bench.json, results/latency.json, results/machine.json |