← Back to section · Tutorials & Labs

Project: Build Your Own PQC Benchmark Suite

A uniform timing framework on top of liboqs: batch-measure key generation, encapsulation, signing, and verification across ML-KEM, ML-DSA, SLH-DSA and more, and emit a reproducible report with medians and spread.

Published 22 November 2026 · 5 min read · PQ Frontier

Project: Build Your Own PQC Benchmark Suite
AI-generated site artwork
Video explainer · Code examples and hands-on projects

“How much slower is ML-DSA verification than Ed25519, really?” “How long does one SLH-DSA signature take?” Rather than trusting numbers produced on someone else’s machine, build a benchmark suite you can reproduce anywhere. This project uses the Python binding of liboqs to write a uniform benchmarking framework: across a set of KEM and signature algorithms it automatically times key generation, encapsulation/decapsulation, and signing/verification, and emits a report table placing medians and interquartile ranges next to the size parameters. Its division of labour with the research-oriented performance articles in this section: those teach you to read other people’s benchmarks; this one teaches you to produce a clean-yardstick benchmark yourself. The boundary up front: a teaching suite’s numbers answer only for the machine and build that ran them. Never cite local results as industry conclusions, and never use them directly for algorithm selection — selection also depends on implementation maturity, side-channel hardening, and certification status, none of which a timing table can see.

Goal and Architecture

The suite has three modules. An algorithm registry: a list of KEM and signature algorithm names (the strings must match liboqs’s enabled algorithm names exactly, such as “ML-KEM-768”, “ML-DSA-65”, “SLH-DSA-SHA2-128s”). At runtime each name is trial-constructed with oqs.KeyEncapsulation(alg); algorithms that fail to construct are recorded as “not enabled on this machine” and skipped rather than crashing the whole suite — different liboqs builds enable different algorithm sets, and that is normal. A timing core: a generic function taking a zero-argument callable and a repetition count, running warm-up iterations first, then recording each run with time.perf_counter_ns(), and returning the sorted raw samples. A report generator: it folds each action’s samples into a median and interquartile range, prints them alongside the public-key and ciphertext byte counts from the details dictionary, and writes a CSV for later plotting.

The most important architectural discipline: all four actions must be timed in exactly the same way, including warm-up and sample counts — otherwise a conclusion like “signing is ten times slower than verification” might be an artefact of two different timing conventions. The second discipline: the report header records the environment — Python version, operating system, CPU model, liboqs version. A benchmark table without an environment header is one you cannot reproduce even yourself three months later.

Walking Through the Core Code

The timing core and the KEM measurement:

import oqs, time, statistics

def bench(fn, warmup=5, samples=50):
    for _ in range(warmup):
        fn()
    times = []
    for _ in range(samples):
        t0 = time.perf_counter_ns()
        fn()
        times.append(time.perf_counter_ns() - t0)
    times.sort()
    return statistics.median(times) / 1e6  # milliseconds

def bench_kem(alg: str) -> dict:
    with oqs.KeyEncapsulation(alg) as kem:
        pk = kem.generate_keypair()
        ct, _ = kem.encap_secret(pk)
        return {
            "keygen": bench(kem.generate_keypair),
            "encap": bench(lambda: kem.encap_secret(pk)),
            "decap": bench(lambda: kem.decap_secret(ct)),
            "pk_bytes": kem.details["length_public_key"],
            "ct_bytes": kem.details["length_ciphertext"],
        }

Three details deserve attention. First, why medians rather than means: OS scheduling, frequency throttling, and background processes inject large spikes into individual samples; a mean gets dragged around by one or two outliers, while a median is naturally immune. Second, warm-up is not optional: the first call pays for lazy dynamic-library loading and cold caches, and mixing it into the samples inflates every number systematically — especially for key generation, which also initializes randomness pools. Third, the closure overhead inside bench(lambda: ...) is not negligible for microsecond-scale actions such as ML-KEM encapsulation; the rigorous approach measures an empty-lambda baseline and subtracts it. This project lists that as a known error term in the report instead of pretending it does not exist — a teaching suite may simplify, but the simplification must be written in the open. The signature side is perfectly symmetric: time generate_keypair, sign(msg), and verify(msg, sig, pk) on an oqs.Signature(alg) object, with the message fixed as 32 placeholder bytes and noted in the report — how signing time scales with message length is exactly what one of the exercises has you measure.

Running and Verifying

Before looking at any ranking, run three self-checks. First, magnitude common sense: ML-KEM’s three actions should sit in the sub-millisecond to few-millisecond range, and SLH-DSA signing should be visibly one to two orders of magnitude slower than its verification; if SLH-DSA signing measures faster than verification, the code is wired backwards. Second, repeatability: run the whole suite three times back to back, and the median of any action should move by no more than ten to twenty percent; larger swings mean something else is competing for the CPU and that round of data is void. Third, cross-check the sizes: the public-key and ciphertext byte counts in the report must match the published FIPS parameter values item by item (for example, the ML-KEM-768 public key is 1184 bytes). If the sizes disagree, you are not measuring the algorithm you think you are — a mistake that genuinely happens between similarly named parameter sets. Only a report passing all three checks deserves to be read against anyone else’s numbers.

Exercises

One: add a constant-time self-check slot — encapsulate the same input repeatedly under a fixed key, observe the spread of the timings, and discuss why “the distribution looks tight” does not prove an implementation is constant-time. Two: make message length a swept variable for signing time and plot how SLH-DSA and ML-DSA scale differently as messages grow. Three: add classical baselines — measure X25519 and Ed25519 in the same framework using the cryptography library, so post-quantum and classical numbers share a stage on your machine for the first time. Four, the advanced one: rerun the suite on a constrained device such as a Raspberry Pi, compare the two reports’ rankings, and write down which conclusions flipped and which did not — the empirical proof that benchmark numbers answer only for their environment.

Summary

What this suite teaches is not which algorithm is fast, but the whole craft of producing trustworthy numbers: warm-up, medians, environment headers, size cross-checks, and openly declared error terms. Master that craft and your first reaction to any benchmark table will be to look for its yardstick and its error bars before its ranking. The final boundary: local numbers speak only for the local machine — when you cite them, cite the environment header with them. That is the basic honesty of benchmarking.

Tags: BenchmarkingliboqsMeasurement MethodML-KEM