language-bench

Fannkuch-redux › Python

Fannkuch-redux Python 3.13

python3. Kernel time 549 ms on the average machine, index 29.9× vs the fastest (28.9×–31.1×), 6.2 MB average memory, 6.2 MB peak. Cold first iteration 553 ms, whole process 572 ms.

How this number came about

  1. The task. Classic Computer Language Benchmarks Game workload: for every permutation of 0..8 (generated in a fixed order) repeatedly reverse the first k+1 elements, where k is the first element, until the first element is 0. Prints an alternating-sign checksum of the flip counts and the maximum number of flips. Every iteration gets a new, never reused instance from the deterministic generator lbgen (this task has no instance: every iteration runs the same workload). 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 python@sha256:90b30ab329c01caa6b7d221bb0e2ab034109044ed38d933d3c2711f4386c1004 containing Python 3.13.18. Hardware, kernel and glibc of every session are listed below.
  3. The source. Exactly this code (hash 75908786814996ad, 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:
N = 9


def setup(args):
    global N
    if args:
        N = int(args[0])


def decode(data):
    return None


def solve(_):
    n = N
    perm1 = list(range(n))
    count = [0] * n
    maxflips = 0
    permcount = 0
    checksum = 0
    r = n
    while True:
        while r != 1:
            count[r - 1] = r
            r -= 1
        perm = perm1[:]
        flips = 0
        k = perm[0]
        while k:
            perm[: k + 1] = perm[k::-1]
            flips += 1
            k = perm[0]
        if flips > maxflips:
            maxflips = flips
        checksum += flips if permcount % 2 == 0 else -flips
        while True:
            if r == n:
                return checksum, maxflips
            p0 = perm1[0]
            for i in range(r):
                perm1[i] = perm1[i + 1]
            perm1[r] = p0
            count[r] -= 1
            if count[r] > 0:
                break
            r += 1
        permcount += 1


def emit(res):
    return res
  1. Build and run.
    run
    python3 /repo/languages/python/harness/harness.py /repo/languages/python/impl/fannkuch/main.py 9
    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
    -
  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).
469 ms515 ms561 ms607 ms653 ms2026-10-27 · AMD EPYC 9V74 80-Core21 iterations · median 492 ms2026-10-27 · AMD EPYC 9V74 80-Core21 iterations · median 479 ms2026-10-27 · AMD EPYC 9V74 80-Core18 iterations · median 569 ms2026-10-27 · AMD EPYC 7763 64-Core16 iterations · median 626 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.

465 ms507 ms554 ms605 ms661 msiteration 1 (cold)last iteration
SessionCPUIterationsColdWarm medianEnd-to-endMachine factorWarm ÷ factorAvg. / peak memorySource
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)21486 ms492 ms504 ms0.890×553 ms6.2 MB / 6.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)21480 ms479 ms506 ms0.892×537 ms6.2 MB / 6.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)18575 ms569 ms612 ms1.079×527 ms6.2 MB / 6.2 MBActions run · raw data · commit
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)16643 ms626 ms633 ms1.076×581 ms6.1 MB / 6.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.890×, 0.892×, 1.079×, 1.076× (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 (553 ms, 537 ms, 527 ms, 581 ms) is averaged geometrically: 549 ms on the average machine (kernel (warm)). The 95% interval 533 ms–570 ms comes from a cluster bootstrap that resamples sessions, then iterations within each.
  3. Index vs fastest. 29.9× = this time ÷ the time of the fastest entry on the same problem, c 15 gcc-O3 (18.4 ms); interval 28.9×–31.1×.
  4. How much was hardware? Raw session medians differ by a geometric factor of 1.133; after dividing out the machine factors they differ by 1.043. 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: 6.2 MB; the highest value seen was 6.2 MB.

Reproduce it

git clone https://github.com/StijnRis/language-bench.git && cd language-bench
pnpm install
pnpm lb verify python --version 3.13 --variant cpython-default --problems fannkuch

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 9.