Example

Separate a benchmark plan from a measured comparison

Run the eligibility record that refuses to compare engines it cannot execute, and learn why an unavailable row is a result, not a failure.

A benchmark has two artefacts that are easy to confuse: a plan describing what would be compared, and a result describing what actually ran. The plan is cheap and can list any engine. The result requires an installed engine, a pinned version, a frozen workload, a measurement point and records that another person can inspect. Reporting the first as the second is the central failure this chapter is written to prevent.

This example runs the plan for three engines. Only the in-process toy backend is available here. vLLM and SGLang are absent, and the program says so with the status UNRUN_FOR_UNAVAILABLE. That is the correct output. The page does not quote a vLLM or SGLang throughput number, because neither engine ran.

Run it

From the canonical repository at commit f958967d70992d7b09d9c75000bd8c543f1644d4:

python examples/ch44/comparison.py --json

Python 3.11 or later, standard library only. No engine installation, network, GPU, model download or credentials are required, and it finishes immediately.

Implementation

The plan is a dataclass with five fields. available is an assertion by the author of the plan, not something the dataclass can verify; reason is where an honest plan records why a row cannot be measured.

@dataclass
class EnginePlan:
    engine: str
    available: bool
    reason: str
    workload: str
    metrics: List[str]

    def to_dict(self) -> dict:
        return asdict(self)


def run_demo() -> dict:
    plans = [
        EnginePlan(engine="inference-lab", available=True, reason="toy backend", workload="fixed prompt set", metrics=["ttft", "throughput", "memory"]),
        EnginePlan(engine="vllm", available=False, reason="not installed", workload="fixed prompt set", metrics=["ttft", "throughput", "memory"]),
        EnginePlan(engine="sglang", available=False, reason="not installed", workload="fixed prompt set", metrics=["ttft", "throughput", "memory"]),
    ]
    return {"plans": [p.to_dict() for p in plans], "status": "UNRUN_FOR_UNAVAILABLE"}

Expected outcome

Observed with the command above (exit 0):

{
  "plans": [
    {
      "engine": "inference-lab",
      "available": true,
      "reason": "toy backend",
      "workload": "fixed prompt set",
      "metrics": [
        "ttft",
        "throughput",
        "memory"
      ]
    },
    {
      "engine": "vllm",
      "available": false,
      "reason": "not installed",
      "workload": "fixed prompt set",
      "metrics": [
        "ttft",
        "throughput",
        "memory"
      ]
    },
    {
      "engine": "sglang",
      "available": false,
      "reason": "not installed",
      "workload": "fixed prompt set",
      "metrics": [
        "ttft",
        "throughput",
        "memory"
      ]
    }
  ],
  "status": "UNRUN_FOR_UNAVAILABLE"
}

The only available row is the toy backend. The two external rows are a record of absence, not a result about either engine. The status names that explicitly.

Mechanism and limitations

Documented: comparison.py returns three EnginePlan records and a status. The example README calls the original file “a toy plan, not availability evidence” and points to the fuller compare_lab.py, engines.py and compare_analysis.py experiment for the actual comparison. The test file asserts three plans, the UNRUN_FOR_UNAVAILABLE status, and that only the first plan is marked available.

Observed: the command exited 0 with exactly the plan and status above. The targeted test command python -m unittest tests.test_ch44_comparison -v ran 3 tests and reported OK. This is a fresh local execution; it is not a measurement of vLLM or SGLang.

Not shown: any external engine’s latency, throughput, memory, output quality or cost; any claim that the toy backend is comparable to a production server; any matched workload or pinned engine revision. The chapter’s own recorded comparison uses a cached Qwen3-0.6B model for in-process experiments, but the external-engine comparison remains NOT_RUN. A row that says available is not evidence that its metrics were collected.

Challenge this result

Change the vLLM row to available=True but leave reason="not installed". Run the program again. It will print a plan that claims an engine it cannot execute. That is the defect this example is designed to expose: the dataclass has no eligibility check. Add a gate that refuses to mark an engine available unless the executable can be found and its version recorded, then explain why even that gate is insufficient without a frozen model revision and workload digest.

Source and verification

Canonical source: examples/ch44/comparison.py at commit f958967d70992d7b09d9c75000bd8c543f1644d4. Tests: tests/test_ch44_comparison.py . Chapter: Benchmarking Against Established Engines . The run above is a fresh local execution on Windows 11 with Python 3.13.15. No external engine, GPU measurement or hosted provider was used.

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.