language-bench

String operations › C

String operations C 15

gcc -O3 -march=native. Kernel time 16.5 ms on the average machine, index 1.02× vs the fastest (1.00×–1.04×), 13.8 MB average memory, 13.9 MB peak. Cold first iteration 19.7 ms, whole process 25.4 ms.

How this number came about

  1. The task. Each iteration receives a 6.7 MB UTF-8 text of 1,000,000 words drawn from an ASCII + Latin + Cyrillic + CJK vocabulary (padded with spaces to a fixed length; the words depend on the iteration). The text is decoded into the language's own string type untimed; the timed part counts bytes, Unicode code points, words (spaces + 1) and non-overlapping occurrences of a needle, and computes a checksum after replacing spaces. No locale-dependent case mapping is used. 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 74a1b558bb5a08ad, 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:
/* Strings are plain UTF-8 byte arrays in C; there is no string library beyond <string.h>. */
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

static char *text;
static size_t len;
static int64_t out[5];

void lb_setup(int argc, char **argv) { (void)argc; (void)argv; }
void *lb_decode(const unsigned char *data, size_t n) { text = (char *)data; len = n; return text; }  /* already UTF-8, NUL terminated by the harness */
void *lb_solve(void *inst) {
  (void)inst;
  long codepoints = 0, words = 1;
  for (size_t i = 0; i < len; i++) {
    if (((unsigned char)text[i] & 0xC0) != 0x80) codepoints++;
    if (text[i] == ' ') words++;
  }
  long needle = 0;
  for (const char *p = strstr(text, "er"); p; p = strstr(p + 2, "er")) needle++;
  char *replaced = malloc(len + 1);
  for (size_t i = 0; i < len; i++) replaced[i] = text[i] == ' ' ? '_' : text[i];
  uint64_t checksum = 0;
  for (size_t i = 0; i < len; i++) checksum += (unsigned char)replaced[i];
  free(replaced);
  out[0] = (int64_t)len; out[1] = codepoints; out[2] = words; out[3] = needle; out[4] = (int64_t)checksum;
  return out;
}
void lb_emit(void *res, void (*sink)(int64_t)) { int64_t *o = res; for (int i = 0; i < 5; i++) sink(o[i]); }
void lb_release(void *inst, void *res) { (void)inst; (void)res; }
  1. Build and run.
    build
    gcc -O3 -march=native -ffp-contract=off -o /work/bin/c-15-gcc-O3-native-string-ops /repo/languages/c/harness/harness.c /repo/languages/c/impl/string-ops/main.c -lm -lpthread
    run
    /work/bin/c-15-gcc-O3-native-string-ops
    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
    21 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).
13.9 ms15.2 ms16.4 ms17.6 ms18.9 ms2026-10-27 · AMD EPYC 7763 64-Core558 iterations · median 17.9 ms2026-10-27 · AMD EPYC 9V74 80-Core690 iterations · median 14.5 ms2026-10-27 · AMD EPYC 9V74 80-Core562 iterations · median 17.8 ms2026-10-27 · AMD EPYC 9V74 80-Core684 iterations · median 14.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.

13.6 ms15.5 ms17.8 ms20.3 ms23.3 msiteration 1 (cold)last iteration
SessionCPUIterationsColdWarm medianEnd-to-endMachine factorWarm ÷ factorAvg. / peak memorySource
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)55820.8 ms17.9 ms26.8 ms1.058×16.9 ms13.8 MB / 13.9 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)69017.4 ms14.5 ms22.3 ms0.892×16.2 ms13.8 MB / 13.9 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)56221.1 ms17.8 ms27.0 ms1.079×16.5 ms13.8 MB / 13.9 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)68417.6 ms14.6 ms23.1 ms0.880×16.6 ms13.8 MB / 13.9 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 1.058×, 0.892×, 1.079×, 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 (16.9 ms, 16.2 ms, 16.5 ms, 16.6 ms) is averaged geometrically: 16.5 ms on the average machine (kernel (warm)). The 95% interval 16.3 ms–16.8 ms comes from a cluster bootstrap that resamples sessions, then iterations within each.
  3. Index vs fastest. 1.02× = this time ÷ the time of the fastest entry on the same problem, c 15 gcc-O3 (16.2 ms); interval 1.00×–1.04×.
  4. How much was hardware? Raw session medians differ by a geometric factor of 1.127; after dividing out the machine factors they differ by 1.016. 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: 13.8 MB; the highest value seen was 13.9 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-native --problems string-ops

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.