language-bench

Binary Trees › Python

Binary Trees Python 3.15

python3. Kernel time 288 ms on the average machine, index 5.58× vs the fastest (4.92×–6.24×), 9.3 MB average memory, 9.4 MB peak. Cold first iteration 292 ms, whole process 315 ms.

How this number came about

  1. The task. Allocates and walks many short-lived binary trees (depth 14 settings from the Computer Language Benchmarks Game): a stretch tree, a long-lived tree, and for each depth 4, 6, ..., 14 many trees that are built, checked and discarded. There is no instance: every iteration runs the same workload. The check sums are the result. 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:3d35e8d5e482ef4f6151426e59208ecde73b7a80e88b38c1b098f60662e5fb91 containing Python 3.15.2. Hardware, kernel and glibc of every session are listed below.
  3. The source. Exactly this code (hash dd51eed44addfd75, 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:
# Binary trees, after the Computer Language Benchmarks Game.
DEPTH = 14


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


def decode(data):
    return None


def make_tree(d):
    if d == 0:
        return (None, None)
    d -= 1
    return (make_tree(d), make_tree(d))


def check_tree(node):
    left, right = node
    if left is None:
        return 1
    return 1 + check_tree(left) + check_tree(right)


def solve(_):
    min_depth = 4
    max_depth = max(min_depth + 2, DEPTH)
    stretch_depth = max_depth + 1
    out = [check_tree(make_tree(stretch_depth))]
    long_lived = make_tree(max_depth)
    for depth in range(min_depth, max_depth + 1, 2):
        iterations = 1 << (max_depth - depth + min_depth)
        check = 0
        for _ in range(iterations):
            check += check_tree(make_tree(depth))
        out.append(iterations)
        out.append(check)
    out.append(check_tree(long_lived))
    return out


def emit(res):
    return res
  1. Build and run.
    run
    python3 /repo/languages/python/harness/harness.py /repo/languages/python/impl/binary-trees/main.py 14
    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).
229 ms259 ms289 ms319 ms349 ms2026-10-27 · AMD EPYC 9V74 80-Core42 iterations · median 240 ms2026-10-27 · AMD EPYC 7763 64-Core30 iterations · median 338 ms2026-10-27 · AMD EPYC 7763 64-Core32 iterations · median 319 ms2026-10-27 · AMD EPYC 9V74 80-Core41 iterations · median 244 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.

227 ms254 ms283 ms317 ms354 msiteration 1 (cold)last iteration
SessionCPUIterationsColdWarm medianEnd-to-endMachine factorWarm ÷ factorAvg. / peak memorySource
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)42250 ms240 ms280 ms0.890×270 ms9.3 MB / 9.4 MBActions run · raw data · commit
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)30342 ms338 ms342 ms1.068×316 ms9.1 MB / 9.1 MBActions run · raw data · commit
2026-10-27AMD EPYC 7763 64-Core Processor (4 cores)32310 ms319 ms343 ms1.090×293 ms9.4 MB / 9.4 MBActions run · raw data · commit
2026-10-27AMD EPYC 9V74 80-Core Processor (4 cores)41250 ms244 ms273 ms0.880×277 ms9.3 MB / 9.3 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×, 1.068×, 1.090×, 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 (270 ms, 316 ms, 293 ms, 277 ms) is averaged geometrically: 288 ms on the average machine (kernel (warm)). The 95% interval 273 ms–306 ms comes from a cluster bootstrap that resamples sessions, then iterations within each.
  3. Index vs fastest. 5.58× = this time ÷ the time of the fastest entry on the same problem, go 1.27 go-amd64-v3 (51.7 ms); interval 4.92×–6.24×.
  4. How much was hardware? Raw session medians differ by a geometric factor of 1.195; after dividing out the machine factors they differ by 1.073. 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: 9.3 MB; the highest value seen was 9.4 MB.

Reproduce it

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

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