Skip to content

Benchmarks: postpile vs the compilers you would otherwise use

Lanes 1 and 2 measured 2026-11-11 on an Apple M1 (macOS 14.8.4, Apple clang 15), Python 3.12.14, with numba 0.68.1, Cython 3.3.1, mypy(c) 2.3.0, NumPy 2.5.1, llvmlite 0.50.0, and TurboPython (tpy-lang) 0.5.1. Reproduce everything with one command from a checkout:

uv run nox -s bench_compare

The comparison runs on Python 3.12, because the competitors stop below the free-threaded 3.14 this repository develops on (Numba supports ≤ 3.13). postpile runs on 3.12 too, so the in-process rows share one interpreter and one process, timed round-robin so that machine drift cancels out of the ratios. Figures are minimum over 40 adjacent rounds. The harness prints each row's coefficient of variation, where a run under load shows itself.

There are two lanes, because compilers with different shapes need measurements with different shapes. Both lanes include the column this project leads with: does the output match CPython?

Lane 1: the ufunc kernels (in-process)

The four kernels of benchmarks/runner.py (element-wise, reduction, transcendental, and a tight nested loop) run over NumPy batches of 10⁵–10⁶ elements. Each contender compiles them from equivalent source. postpile and Numba use the same decorator model (POST adopted Numba's @vectorize/@guvectorize wholesale). Cython uses typed memoryview loops with boundscheck=False, the release mode; postpile's --release builds keep their bounds checks, and --unchecked, which drops them, changed no kernel's time beyond noise on Linux x86_64. mypyc compiles the same loops as plain annotated Python. Numba's JIT warmup happens before timing, so the row reports steady state and does not charge for compilation.

min time, ms postpile-c postpile-qbe postpile-llvm numba cython numpy cpython mypyc
square (10⁶) 0.243 0.422 0.193 0.202 0.188 0.855 73.8 140.9
dot (10⁵×64) 3.192 3.286 3.158 3.254 3.548 8.570 58.9 901.5
gaussian (5·10⁵) 1.306 1.407 1.306 1.396 1.281 2.090 68.3 123.5
matmul (10⁵ 4×4) 4.756 3.786 4.712 3.399 4.701 5.306 118.7 3278.6

The geomean of min-time ratios, relative to postpile-c, reads: cpython 52.0× slower · numpy 2.03× slower · numba 0.90× · cython 0.96× · postpile-llvm 0.94× · postpile-qbe 1.11× · mypyc 321× slower.

In short, Cython is within 5%; Numba is ~1.1× ahead, on matmul only. (On 2026-08-06 the same lane read Cython 0.98×, Numba 0.87×, CPython 54.6×; Numba 0.68 no longer leads dot.) The square row is the story of a measured fix: the first run of this page found the element-wise loop 1.8× behind Cython, the diagnosis was the runtime-strided char* walk defeating the vectorizer, and the C and LLVM backends now emit a unit-stride fast path (C 0.352 → 0.225 ms; LLVM 0.345 → 0.189 ms, the fastest postpile row on the page). QBE did not get the port: it has no vectorizer to feed, so the specialization would buy one multiply per element at best. Its square gap has different causes, and matmul is where its hand-rolled unroll wins instead. Numba's remaining edge is dot and matmul, reduction and unrolling territory. Part of the price is chosen: reassociation and FMA change the bits, and postpile refuses both (see lane 2's match column for what accepting them looks like). That price is now measured: rebuilding the identical-source dot with -ffp-contract=fast runs ~5% faster (~9% with -O3 added) and its checksum immediately stops matching CPython. That is roughly what exactness costs on a reduction; part of the JIT edge is made of the same thing. postpile beats NumPy ~2× on these fused kernels and CPython 52×. The mypyc row lands where it does because mypyc is not a numeric compiler: element access through the C API leaves it up to 15× slower than the interpreter it compiles for.

Lane 2: the identical source (whole programs)

benchmarks/wholeprog.py goes further than "equivalent source": each of the first three kernels (in benchmarks/lowlevel/) is one file that is valid Python, valid POST Python and valid TurboPython at once, containing only flat list[float] data, without imports or timing calls. Every runtime compiles and runs the same bytes, so no port can be unfair. Timing is a two-point slope (each program built with a small and a large internal iteration count; per-iteration time is the difference over the difference), so process startup and data fill cancel and no language needs a timing API. Each kernel perturbs one input element per iteration (the first draft did not, and tpy's C++ optimizer legally collapsed the repeated pure dot calls into one, producing a negative slope); the perturbation makes every call distinct for every runtime equally. Each program prints a checksum; the match column compares it with CPython's at the same iteration count, byte for byte.

per-iter, ms cpython C by hand postpile-c postpile-llvm postpile-qbe tpy -O
square 13.7 0.254 0.219 exact 0.249 exact 0.612 exact 0.391 DIFFERS
dot 40.3 1.153 1.057 exact 1.054 exact 1.074 exact 1.651 DIFFERS
matmul 119.3 0.176 0.331 exact 0.315 exact 2.133 exact 1.644 DIFFERS

2026-11-11, the default build (growing int). The kernels have changed since the first runs of this lane: square perturbs a moving index, with higher iteration counts throughout (see the last finding below). The 2026-08-07 table (cpython 57.2 / 31.1 / 171.5 ms, postpile-c 0.39 / 1.84 / 0.62, tpy 2.22 / 1.09 / 1.37) is therefore not comparable row for row. postpile-c now leads tpy on each kernel, 1.8× on square, 1.6× on dot and 5× on matmul, and tpy still differs from CPython on each row.

The findings below stand as they were written (2026-08 to 2026-09):

The speed verdict inverted between runs: postpile-c now leads TurboPython ~6× on square and ~2× on matmul, still matching CPython byte-for-byte; tpy still differs on every row. The previous run had tpy 2–8× ahead, and reading its compiler (the wheel is pure Python, fully inspectable) explained why: tpy's generated C++ and its std::vector<double> list live in one translation unit, so every element access inlines. postpile's list runtime was a separate translation unit: an out-of-line function call per element access, even after ADR-0053 removed the checks. The fix was proportionate to the diagnosis: release builds now link with -flto, and on identical binaries the controlled same-hour ladder measured square 12.6× faster, matmul 17×, dot 2.8×, with output bytes unchanged on all three (the loaded table understates dot's gain: quiet-machine, it went 2.67 → 0.97 ms). tpy's lead now rests on dot alone, where an order-preserving reduction is latency-bound by its serial FP-add chain; postpile's 0.97 ms for 10⁶ elements is that floor (~4 cycles per element), and tpy's margin there is bought with the contraction that breaks its checksums.

The DIFFERS column is characterized now: it is not rounding noise. tpy 0.5.1 prints checksums 1.4% away from CPython's, including on square, whose kernel contains no multiply-add to fuse. The divergence enters through the data: the shared fill() routine's PRNG line (s * 1103515245.0 + 12345.0) is a fused-multiply-add candidate, tpy's g++ toolchain contracts it by default (-ffp-contract=fast), and the changed rounding rewrites the pseudo-random sequence before any kernel runs. tpy's rows are different answers computed over different inputs, with no diagnostic. postpile's three-address emit leaves default contraction nothing to fuse; its exactness holds at any compiler flag by construction, and the differential suite re-proves it on every build.

postpile's own two container types opened 24× apart on this code; two ordered fixes later the C backend's gap is ~1.6×. First ADR-0053 elided the IndexError exactly where a loop's own shape proves it dead (square 5.4 → 3.3 ms). Then the cross-TU inlining removed the call around what remained (3.3 → 0.39 ms, against 0.25 ms for the same loop as Array[Float64] in the same session). Ordinary list code keeps getting faster without ever leaving CPython's answers. The lane's widest gap is now postpile's own: QBE emits assembly and the LLVM backend emits native objects in-process, so neither can take part in link-time inlining, and their list rows trail the C backend by up to ~16×. That makes the LLVM accessor-inlining slice the page's next ordered work, ahead of the ADR's stage B for companion-list stores. Update, 2026-09-29: that slice landed. This lane re-run on a quiet machine (python -m benchmarks.wholeprog, without the tpy row) gives postpile-llvm square 3.39 → 0.43 ms, dot 2.72 → 0.95 and matmul 5.56 → 1.46, and postpile-qbe, which writes the accesses in place for want of an inliner and loads a list parameter's length and data pointer once where nothing can resize it, square 3.85 → 1.02, dot 2.85 → 1.09 and matmul 7.30 → 3.44, all checksums exact. ADR-0053's stage B landed on 2026-09-30 and took square, per call, from 0.57 to 0.24 ms on C, 0.42 to 0.15 on LLVM and 1.16 to 0.57 on QBE. It also exposed a flaw in this lane: with the loop free of side exits, the C backend's inlining saw that each iteration changed only x[0], and collapsed the repetition to 0.08 ms. square's main now perturbs a moving index and folds one changing output into the checksum at each iteration, as dot's design already required, and runs 333 iterations (up from 33), because a kernel ten times faster needs ten times the iterations for a stable slope. matmul's computed indices keep the IR's IndexError check. The LLVM backend kept a second one after it, the runtime's backstop, until it was told a list's length is never negative. With that fact -O2 folds the second into the first: postpile-llvm matmul went from 1.43 to 0.87 ms (2026-09-30).

Lane 3: against C (the speed index)

The same harness times each program in benchmarks/lowlevel/ against a C version of it, the same algorithm written as a C programmer would (plain arrays, stack data, no bounds checks). The same cc builds it at postpile's -O2 with -ffp-contract=off, so it computes CPython's numbers too (ADR-0067). The programs are low-level: no classes, polymorphism, coroutines or parallelism. A runtime's speed index is the geometric mean of its time over C's; 1.00 is parity.

Since 2026-11-10 an executable's int grows past 64 bits as CPython's does (ADR 0075), and that default build is the headline; --no-grow-ints builds the 64-bit int, shown beside it.

time ÷ C's c llvm qbe c, 64-bit llvm, 64-bit qbe, 64-bit CPython
square 1.01 0.93 1.28 0.99 0.97 1.58 87.9
dot 1.01 1.03 1.04 0.97 1.06 1.01 65.2
matmul 0.48 0.77 2.15 0.53 0.83 1.98 430
nbody 1.51 1.69 8.50 1.50 1.73 8.41 93.2
spectral_norm 1.03 1.00 4.42 1.06 1.01 4.67 157
mandelbrot 1.11 1.10 2.13 1.01 1.07 1.58 74.2
fannkuch 3.43 5.33 10.9 1.41 1.13 4.26 32.7
sieve 1.13 2.77 4.85 1.00 1.34 2.89 121
nqueens 1.71 3.14 8.00 1.36 1.64 3.39 19.1
matmul2d 2.87 10.4 13.4 3.10 9.90 13.8 159
levenshtein 7.10 8.03 16.2 1.49 1.44 6.14 137
wordfreq 1.55 1.88 1.98 1.46 1.78 1.75 5.44
life 1.71 1.70 3.27 1.33 1.37 3.67 217
index 1.55 2.11 4.22 1.23 1.46 3.25 79.6

The table was taken on 2026-11-16 on Linux x86_64 (16 cores, GCC 16.2 at -O3, Python 3.14.10) with python -m benchmarks.wholeprog --both-int-modes, which times each backend with both ints alternated per program, in --release on a quiet machine (load 1.2 to 1.7). A second run the same hour read 1.55, 2.09, 4.20 and 1.20, 1.45, 3.27. All rows print CPython's output. The growing int costs nothing where a program's integers are proven bounded or are floats. The range proofs of ADR 0075's step 5 put bounds on life's cells and sieve's counter (both near C's time on c since 2026-11-14). The programs levenshtein (7.1), fannkuch (3.4) and nqueens (1.7) add list elements and counters that no proof bounds yet, so each operation there tests for a reference and checks for overflow. On LLVM the same programs cost more, and matmul2d is 10 times C's time with either int, which is not examined. On the Apple M1 (2026-11-14, under load) the index read 1.86 on c and 1.98 on llvm.

Since 2026-11-12 --release keeps the checks, the overflow check of the 64-bit int and the Array bounds check, and --unchecked drops them (ADR-0002, A194). The project offers both; the table above is --release. The table below was taken on the same machine on 2026-11-14, before the range proofs, as the best of three rounds per program of python -m benchmarks.wholeprog with and without --unchecked:

index c llvm qbe c, 64-bit llvm, 64-bit qbe, 64-bit CPython
--release 1.78 2.48 4.77 1.22 1.47 3.42 73.2
--release --unchecked 1.80 2.46 4.83 1.18 1.47 2.97 72.7

With the growing int the two builds are the same program within noise, since nothing in these programs has a check left to keep. With the 64-bit int the checks cost 1.03 on C and 1.15 on QBE by geometric mean, most of it in life (1.22 on C, 1.90 on QBE). On LLVM, which knows that a failed check does not return, they cost nothing measurable. With GCC, matmul2d takes 3.1 times C's time on the C backend with the 64-bit int, against 1.47 on the M1; that gap is not examined. Every row of both prints CPython's output (notes/measurements.md, 2026-11-14).

With the 64-bit int, the index was 1.45 on the C backend at the first full reading (2026-10-27). Since then:

  • A list[bool] holds one byte per element (ADR 0068), which took sieve from 2.75 to C's time.
  • A proven s[i] == x on an ASCII string compares one byte, and the LLVM backend inlines that compare (levenshtein 2.35 → 1.32).
  • A nest of short literal loops is proven in range by one test before it (ADR 0053's amendments; matmul 3.30 → 1.71).
  • for w in s.split(): walks the words without the list, looking a word used only as a dict key up by its span of the string (ADR 0069; wordfreq 2.92 → 1.44).

With the 64-bit int, no program is more than 2× off C on the C backend; what remains over 2× there is matmul2d on LLVM and QBE, which has no optimizer, on most programs. python -m benchmarks.wholeprog --check benchmarks/lowlevel/baseline.json (the baseline is the default build's, 2026-11-10) fails when a program's ratio grows by more than 25%. Run it on a quiet machine. A loaded one moved mandelbrot by 40% in one run, and once, under a load average of 18, gave CPython a negative time per iteration on dot; the lane now reports that as a failed measurement.

Caveats

One machine and four kernels are enough to place postpile among comparable compilers. The interesting delta, the order-preserving share of Numba's dot/matmul edge, is tracked as a work item. This page changes only when the harness is re-run and says so. Raw rows: nox -s bench_compare prints both tables and takes --json for the in-process lane. The tpy row needs its wheel, which is not on PyPI at source; the nox session picks it up from sandbox/ when present. When it is absent, that row skips and everything else reproduces.