language-bench

Hash map › C

Hash map C 15

gcc -O3. Kernel time 33.6 ms on the average machine, index 1.08× vs the fastest (0.98×–1.20×), 20.8 MB average memory, 25.2 MB peak. Cold first iteration 33.5 ms, whole process 38.5 ms.

How this number came about

  1. The task. 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. Every iteration gets a new, never reused instance from the deterministic generator lbgen (streamed to the program on standard input). A separate check compares an order-sensitive hash of the complete result of 20 iterations with the generator's reference; this was the case in every session.
  2. The environment. A fresh GitHub-hosted VM per session runs the pinned Docker image gcc@sha256:dc99c5016a0fb74d4e9a392e7892966ec7f358af744799bd3479239598f79d45 containing gcc (GCC) 15.3.0. Hardware, kernel and glibc of every session are listed below.
  3. The source. Exactly this code (hash f0d4abfdbf7f21c4, in git at the commit of each session) is the kernel: it only decodes the instance and solves it. It is built together with the language's one harness, which owns the clock, the loop and the output:
/* C has no standard hash map: a simple open-addressing table with linear probing. */
#include <stdint.h>
#include <stdlib.h>

#define CAP (1u << 21)

static uint32_t *keys; /* key + 1, 0 = empty */
static uint32_t *vals;
static uint32_t distinct;
static const int32_t *ins, *look;
static size_t n;
static uint64_t out[3];

static uint32_t slot(uint32_t k) {
  uint32_t h = (k * 2654435761u) >> 11; /* Fibonacci hashing into 21 bits */
  while (keys[h] != 0 && keys[h] != k + 1) h = (h + 1) & (CAP - 1);
  return h;
}

void lb_setup(int argc, char **argv) { (void)argc; (void)argv; }
void *lb_decode(const unsigned char *data, size_t len) { n = len / 8; ins = (const int32_t *)data; look = ins + n; return out; }
void *lb_solve(void *inst) {
  keys = calloc(CAP, sizeof *keys);
  vals = calloc(CAP, sizeof *vals);
  distinct = 0;
  for (size_t i = 0; i < n; i++) {
    uint32_t k = (uint32_t)ins[i];
    uint32_t h = slot(k);
    if (keys[h] == 0) { keys[h] = k + 1; distinct++; }
    vals[h]++;
  }
  uint64_t checksum = 0;
  for (uint32_t h = 0; h < CAP; h++)
    if (keys[h]) checksum += ((uint64_t)keys[h] - 1) * (uint64_t)vals[h];
  uint64_t hits = 0;
  for (size_t i = 0; i < n; i++) {
    uint32_t h = slot((uint32_t)look[i]);
    if (keys[h]) hits += vals[h];
  }
  out[0] = distinct; out[1] = checksum; out[2] = hits;
  return inst;
}
void lb_emit(void *res, void (*sink)(int64_t)) { (void)res; for (int i = 0; i < 3; i++) sink((int64_t)out[i]); }
void lb_release(void *inst, void *res) { (void)inst; (void)res; free(keys); free(vals); }
  1. Build and run.
    build
    gcc -O3 -ffp-contract=off -o /work/bin/c-15-gcc-O3-hashmap /repo/languages/c/harness/harness.c /repo/languages/c/impl/hashmap/main.c -lm -lpthread
    run
    /work/bin/c-15-gcc-O3-hashmap
    kernel loop
    The harness reads and decodes an instance (untimed), times only solve with the language's monotonic clock, and repeats until the summed kernel time reaches 10 s (at least 3 iterations, no other cap). The first iteration is the cold time; the warm time is the median of the iterations after the first 2 s of kernel time. Memory is read from the container's cgroup by a sampler outside the process.
    end-to-end
    hyperfine runs the same binary for exactly one iteration (process start to exit, with the instance read from a file) and records wall-clock time and peak resident memory; reported next to the kernel time.
    binary size
    17 kB
  2. Many sessions, many iterations. The benchmark was measured in 4 independent sessions between 2026-10-27 and 2026-10-27, on 2 CPU models. Within a session the execution order of all benchmarks was randomised. Each dot below is one warm kernel iteration (at most 100 evenly spaced ones per session are shown); the black bar is the session median; orange dots are flagged outliers (kept in the data).
27.2 ms32.8 ms38.4 ms44.1 ms49.7 ms2026-10-27 · AMD EPYC 9V74 80-Core306 iterations · median 32.7 ms2026-10-27 · AMD EPYC 7763 64-Core306 iterations · median 32.7 ms2026-10-27 · AMD EPYC 7763 64-Core280 iterations · median 35.2 ms2026-10-27 · AMD EPYC 9V74 80-Core321 iterations · median 30.6 ms

Warm-up curve

Kernel time of every iteration in order, one line per session (log axis; orange dot: the cold first iteration). Just-in-time and garbage-collected runtimes need a while to settle; compiled languages are flat from the start.

26.9 ms32.2 ms38.5 ms46.0 ms55.0 msiteration 1 (cold)last iteration
SessionCPUIterationsColdWarm medianEnd-to-endMachine factorWarm ÷ factorAvg. / peak memorySource
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)30631.0 ms32.7 ms38.3 ms0.892×36.6 ms20.9 MB / 25.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)30632.9 ms32.7 ms39.0 ms1.068×30.6 ms20.5 MB / 25.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)28036.2 ms35.2 ms40.1 ms1.090×32.3 ms20.8 MB / 25.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)32131.1 ms30.6 ms33.4 ms0.880×34.8 ms20.7 MB / 25.2 MBActions run · raw data · commit

The table is computed from the raw values: download every iteration and repetition of this benchmark (CSV), or the complete session files linked above. Each “Warm median” is the median of the kernel iterations after the first 2 s; “÷ factor” divides it by the machine factor.

  1. Cancelling out the hardware. GitHub gives every session a different computer, and some are faster than others, so raw times from different sessions cannot be compared directly. To fix that, every session gets a machine factor: how many times longer programs take on that machine than on the average machine. A factor of 1.2 means “20% slower than average”. We find these factors by looking at benchmarks that ran in several sessions: if the same programs are consistently 20% slower in one session, that machine is 1.2× slower. The factors for this benchmark's sessions are 0.892×, 1.068×, 1.090×, 0.880× (click a date in the table above for the session's details). Technically: we fit log(time) = benchmark + machine across all 8 sessions at once; see the methodology.
  2. Combining sessions. Sessions, not iterations, are the independent samples. Each session's warm median divided by its machine factor (36.6 ms, 30.6 ms, 32.3 ms, 34.8 ms) is averaged geometrically: 33.6 ms on the average machine (kernel (warm)). The 95% interval 31.5 ms–35.9 ms comes from a cluster bootstrap that resamples sessions, then iterations within each.
  3. Index vs fastest. 1.08× = this time ÷ the time of the fastest entry on the same problem, c 16 gcc-O3-native (31.0 ms); interval 0.98×–1.20×.
  4. How much was hardware? Raw session medians differ by a geometric factor of 1.060; after dividing out the machine factors they differ by 1.088. The overall model leaves 1.057× of unexplained noise.
  5. Memory. A sampler on the host reads the anonymous memory of the container's cgroup every few milliseconds. The average is weighted by time over the timed kernel regions only (instance generation and decoding excluded), then averaged over sessions: 20.8 MB; the highest value seen was 25.2 MB.

Reproduce it

git clone https://github.com/StijnRis/language-bench.git && cd language-bench
pnpm install
pnpm lb verify c --version 15 --variant gcc-O3 --problems hashmap

Needs Docker. The command builds the harness and the program in the pinned image and checks the result against the generator's reference; the full timed measurement runs in CI sessions. The parameters of the problem are none.