A comparison, measured
Programming language shootout.
Ten problems, two styles, and the choices behind the measurements.
Recorded on an Apple M4 Max, 12 November 2026 UTC. Local inputs, twelve x2c samples; other-language results use an earlier calibration. These are local comparisons, not published Benchmarks Game results.
A small numerical loop and a DNA-processing pipeline ask different things of a language. One spends its time on arithmetic. Another creates strings, looks up keys, and moves bytes between buffers. A single score hides those differences.
This experiment starts with ten Computer Language Benchmarks Game problems. Each has two x2c implementations: an idiomatic version built with ordinary collections and APIs, and a tuned version that specializes the work where it matters. The question is what changes when we move between those styles, and how much code that change needs.
In the recorded November 2026 local-input snapshot, across the eight problems shared by all eight implementation columns, tuned x2c takes 1.20 times the C elapsed time, with 0.89 times the C source lines. Those are geometric means of matched problem ratios. The individual programs tell a more useful story than that summary.
Start with the individual problems
Tuning makes its largest differences in the text-processing programs. On k-nucleotide, elapsed time falls from 102.8 ms to 17.4 ms. FASTA falls from 22.6 ms to 4.4 ms, and reverse-complement from 12.4 ms to 2.5 ms. Each pair solves the same problem specification, but changes how the program represents or moves its data.
Other pairs barely move. The two binary-trees sources are identical; their 26.6 ms and 26.8 ms medians are separate measurements of that same source. Pi digits also changes little: 281.5 ms becomes 269.2 ms. There is no single transformation that explains every row.
These are small local inputs. Mandelbrot's C baseline is 2.8 ms, while pi digits takes 263.4 ms. A ratio should be read with its absolute time; it does not tell us how much time a larger application would save.
Put the representation where the work is
The n-body simulation keeps five bodies moving under mutual gravity. The idiomatic implementation uses heap objects and an Array of body pairs. The tuned version keeps the five bodies in a native array of structs and visits each pair with two loops. It still uses Vec3 methods and required reference parameters for the physics.
On this input, n-body goes from 72.9 ms in 102 source lines to 33.2 ms in 82 lines. The C program takes 32.8 ms. Here, making the fixed shape explicit also removes code: the tuned program does not need a separate collection of pair objects.
K-nucleotide makes a different representation choice. Both implementations count all sliding windows for their requested lengths. The idiomatic program creates a String key for each window and updates a general Map. The tuned program uses MapSubInt, whose keys borrow spans of the original sequence:
MapSubInt counts = MapSubInt.new();
for (int i = 0; i + width <= sequence.len(); i++)
counts.increment(sequence.substring(i, width));The tuned program retains the sequence while those views are in use. It materializes strings where the frequency report needs them. This removes repeated key creation from the counting loop without replacing the required growing-map algorithm. Its 17.4 ms still exceeds the C baseline's 9.3 ms; the shorter implementation does not erase every cost.
Move bytes in batches
The idiomatic reverse-complement program reads FASTA lines, collects each sequence in a Buffer, and builds its output one line at a time. The tuned program reads 16 KiB chunks with fread, uses a complement lookup table, transforms its typed character buffer in place, and batches output before calling write_all.
That version grows from 47 to 67 source lines, while its measured time falls from 12.4 to 2.5 ms. The added code handles chunk boundaries, headers, and output buffering. It is useful code to write when this work matters; it is also more code to understand and maintain.
FASTA follows a similar route. The ordinary version builds output lines with a Buffer and stores probability choices as objects. The tuned version uses typed probability storage and a native output buffer. It grows from 65 to 82 lines and drops from 22.6 to 4.4 ms. These comparisons change several implementation details together. They do not isolate the contribution of each change.
Speed does not have one source-size cost
Tuned n-body and spectral-norm are both shorter than their idiomatic counterparts. The text-processing variants usually add code. Regex-redux grows from 61 to 97 lines: it keeps PCRE2 and independent pattern-counting threads, but uses borrowed match-data blocks instead of constructing capture Lists, plus typed buffers for substitutions. Its time falls from 26.4 to 13.3 ms.
Pi digits already delegates arbitrary-precision arithmetic to GMP in both versions. The tuned version uses fused multiply-add and multiply-subtract operations to avoid intermediate products; it retains both extracts required by the problem. This is a smaller change, and the measured difference is smaller too.
Source lines here mean nonblank lines after language-aware comment removal. They are a way to inspect the amount of source, not a measurement of clarity. The recorded dataset also includes normalized gzip bytes. On the shared cohort, tuned x2c uses 0.89 times C's source lines but 1.11 times its compressed source bytes. The answer changes with the measure.
Place the results beside the other programs
This view includes only the eight problems with an entry in every column. Tuned x2c's elapsed-time ratio is 1.20; Rust's is 1.17. Idiomatic x2c is 2.82 relative to C, with 1.19 times Python's source lines; tuned x2c uses 1.29 times Python's lines.
These are selected implementations, not rankings of what each language can do. The source choices, libraries, process model, and input sizes all matter. Java starts a fresh JVM for each sample, including startup and JIT compilation; the warmup process does not warm the next JVM. Its number is not a steady-state server measurement.
The missing contributions also matter. K-nucleotide has no Rust, C++, Go, or Java entry in this environment. Binary-trees has no Python entry. Those problems remain visible in the x2c comparisons above, but are excluded from the shared summary rather than silently given substitute scores.
What was measured
The figures use the recorded 12 November 2026 UTC snapshot on an Apple M4 Max, with the suite's local input profile. Each x2c result is the median of twelve fresh processes after one warmup. Foreign-language measurements come from the pinned earlier calibration; they were not rerun alongside these x2c samples. The canonical-size suite remains unrun.
The measured source revision is ccc7e475869cf93f91637f283761a57dfd92715b. Published commit 2ef0360087 holds the same benchmark sources. The explanations above describe those measured sources. Some current example sources have since changed. The downloadable results, measurements, and provenance identify the snapshot, its inputs, and included entries.
The useful next step is to read a pair of implementations for a workload you recognize. Below are the complete current programs, followed by commands for checking them locally. The charts describe the recorded snapshot, not a new run of those current files.
Measured benchmark sourcesFigure provenanceFull results and inputsMeasurements CSV
Read the complete programs.
These are the current sources. Open a problem to read either version or compare both. The article above explains the recorded snapshot.
01 / 10
n-body
Advance five bodies under mutual gravity, then report the system's energy.
Problem specificationRead and compare source
02 / 10
spectral norm
Estimate an implicit matrix's spectral norm through repeated matrix-vector products.
Problem specificationRead and compare source
03 / 10
fannkuch-redux
Enumerate permutations, reverse prefixes, and report the checksum and largest flip count.
Problem specificationRead and compare source
04 / 10
Mandelbrot bitmap
Test points in the complex plane and write a binary PBM bitmap.
Problem specificationRead and compare source
05 / 10
fasta
Generate repeated and random DNA sequences with the prescribed probability distributions.
Problem specificationRead and compare source
06 / 10
k-nucleotide
Count DNA fragments in growing maps and report frequencies and requested fragment counts.
Problem specificationRead and compare source
07 / 10
reverse-complement
Read FASTA records and write each sequence's reverse complement.
Problem specificationRead and compare source
08 / 10
binary-trees
Allocate and check complete trees, including every leaf, at a range of depths.
Problem specificationRead and compare source
09 / 10
regex-redux
Count regular-expression matches and apply an ordered chain of substitutions to DNA input.
Problem specificationRead and compare source
10 / 10
pidigits
Generate decimal digits of pi with the prescribed arbitrary-precision spigot algorithm.
Problem specificationRead and compare source
Run the suite
Check the programs locally.
From a repository checkout with the compiler built, run all official fixtures and quick-profile comparisons, or select individual problems.
make shoot-check
# Check two selected problems.
python3 examples/shootout/tools/shootout.py check --profile quick \
--only mandelbrot --only binarytreesThe full reference suite needs the language toolchains, PCRE2, and GMP. The suite guide lists dependencies, build options, input sizes, and measurement methods.