Projects / Lang Lab
Benchmarking backend languages by CPU instructions, not seconds
Lang Lab measures how much CPU work the same hand-written algorithm costs in 16 backend languages against a C baseline: bit-exact instruction counts under QEMU instead of wall-clock time, on free CI, refreshed when a language ships a new version.
Context
Choosing a backend language is a systems decision, and the numbers available to make it are either about frameworks (TechEmpower), about syntax breadth (Rosetta Code), or timings nobody can reproduce. I wanted a ranking I could regenerate on demand and defend line by line.
Problem
Timing seconds on shared CI runners gives 20 to 30 percent noise: variable hardware, noisy neighbours, unpredictable turbo. On top of that, the runtimes are nothing alike (ahead-of-time natives, interpreters, JITs with concurrent garbage collectors, the BEAM), so measuring them uniformly, and proving that every implementation did the same work, is the actual problem.
Constraints
Free GitHub-hosted runners only, no self-hosted hardware. Results reproducible bit for bit for native and interpreted languages. Automatic maintenance: a new language version should land as a pull request, not as a chore. Every tradeoff disclosed next to the results.
Decisions
- Count instructions, not seconds. QEMU user-mode with the TCG
insnplugin counts the guest's instructions deterministically, the technique rustc-perf uses to track the Rust compiler. Valgrind was rejected: it segfaults on Go and measures the wrong process for launcher runtimes. - A differential metric. Each benchmark runs at two sizes and reports
I(n₂) − I(n₁), normalised to C = 1.00×. Subtracting the two runs cancels process startup and JIT warmup and leaves the algorithm's work. - A checksum gate. Every benchmark has a reference checksum that each implementation must reproduce bit for bit before its count is accepted, so a fast but wrong solution cannot reach the leaderboard. Implementations are hand-written (real SHA-256 rounds, hand-rolled bignum limbs, an int8 matmul without BLAS) because the suite isolates what the language does to the algorithm, not what its ecosystem's C libraries do.
- Pinned, disclosed runtime configurations. The plugin sums instructions over every thread, so managed runtimes run single-threaded:
GOMAXPROCS=1, the JVM's serial collector, Node's--single-threaded, workstation GC and single-tier JIT on .NET, one BEAM scheduler. No configuration turns a garbage collector off; allocation-heavy benchmarks measure real collection work. - Measure the metric itself. Instructions are not seconds. Against wall-clock on compute-bound code the metric predicts magnitude at R² 0.91 (log-log) and rank order at Spearman 0.87, worse for JIT and syscall-bound code, and that characterisation is published next to the results. A separate scaling track measures wall-clock parallel speedup,
T1/TPat 1, 2 and 4 cores, natively, because instruction counts are blind to parallelism. - One harness lesson. For a while every complex runtime exited silently under QEMU, and they looked impossible to emulate. The cause was that qemu-user does not resolve a bare command name through PATH; natives were invoked by absolute path and worked. Resolving
argv[0]fixed every language. No output does not mean it cannot be emulated.
Results
16 languages plus the C baseline across 19 benchmarks, 18 of them ranked (message-ring is shown but excluded, because instruction counts are syscall-blind for context-switch primitives). Overall geomean against C: Fortran 1.05×, Rust 1.11×, C# 1.49×, Go 1.64×, Swift 2.03×, VB.NET 2.11×, Scala 2.39×, Kotlin 2.53×, OCaml 2.68×, Java 2.92×, JavaScript 5.09×, Elixir 22.3×, PHP 32.2×, Ruby 75.3×, Python 104×, Perl 146×. The JVM ratios move between ISAs and between CI runs (up to 1.9× in the 14 October runs, within 10% in the 22 October one), so they are reported per ISA and run.
The per-benchmark view is where it gets interesting. Garbage-collected runtimes beat C on allocation: OCaml at 0.19×, Scala and Kotlin at 0.28× and Java at 0.33× on binary-trees. VB.NET runs on the same .NET runtime as C# but keeps Visual Basic's default overflow checks, which cost it about 1.4× C#'s work. Rust beats C on blur at 0.48×, where LLVM auto-vectorises and gcc -O2 does not. On the scaling track most native and VM runtimes land near 4× on 4 cores, and the GIL languages reach it through processes while their thread variants flatline at 1.0×.
COBOL has a side study (opens in new tab) outside the ranking, on the 15 benchmarks that need no hand-rolled machinery. Written naturally it costs 26× to about 7,000× C on both GnuCOBOL 3.2 and GCC's gcobol; only a restricted single-verb style on gcobol reaches about 5× to 7× C on integer loops. Along the way the study found two gcobol miscompiles, kept as minimal reproducers.
The pipeline runs on free runners: a weekly version watcher opens a pull request bumping the pinned versions, the merge rebuilds the version-pinned Docker image per language and measures under QEMU, and the result history lives in the repository.
Next
Parallel variants for the scaling track are pending for Java, JavaScript, OCaml, VB.NET and Fortran, and the project is still v0. From here the plan is to add axes rather than languages and to keep the fairness audit open: if a language looks unfairly slow, a pull request that keeps the checksum gets merged and credited.