language-bench

Hash map

One million inserts/updates and one million lookups in a hash map.

memory-bounddata-structures

What is measured

Each iteration receives 1,000,000 keys to count (drawn from 500,000 values) and 1,000,000 keys to look up (MINSTD, seed = iteration). The timed part fills a hash map with the counts, computes a checksum over it and looks up all keys; it returns the number of distinct keys, the checksum and the number of hits.

Pseudocode

insert_keys, lookup_keys = decode(instance)      # untimed
start timer
counts = empty hash map
for key in insert_keys: counts[key] += 1
checksum = sum over (key, c) of key * c
hits = sum over lookup_keys of counts.get(key, 0)
stop timer
hash (size(counts), checksum, hits)

Reveals: Insertion, lookup and hashing speed of the standard hash map.

Caveat: Key distribution and hash implementation dominate. Standard-library maps are used as they ship: Rust's default SipHash is deliberately DoS-resistant and slower; C has no standard map so a simple open-addressing table is hand-written; C++ uses std::unordered_map, Java HashMap, C# Dictionary, Ruby Hash and PHP arrays.

Results (newest release of each language)

Language / buildTime (× vs best)
C 16 · gcc -O3 -march=nativedefault31.0 ms (1.00×)
C 16 · gcc -O231.2 ms (1.01×)
C 16 · gcc -O332.4 ms (1.05×)
Go 1.27 · GOAMD64=v3 go build95.5 ms (3.08×)
Go 1.27 · go builddefault100 ms (3.23×)
Python 3.15 · python3default397 ms (12.8×)

Click a language to see the source code, build flags, every session and how the number was computed.