# Measured results

> Compare recorded workloads, inspect the baselines, and reproduce the results.

The biggest gains here come from doing less work. Lazy merge reads only enough to produce a prefix. An indexed priority queue finds each entry by value after building its index. The table shows exactly what was timed or checked.

## Workloads and baselines

| Claim                                                | Baseline                                               | Class                  | Address                                                                                                                                       |
| ---------------------------------------------------- | ------------------------------------------------------ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Roaring bitset intersection count, 528× faster       | a manual `Set` loop over two 100,000-ID ranges         | algorithmic comparison | [Bitset timings](/benchmarks/#bitset)                                                                                                         |
| First 32 sorted IDs from eight lists, 408× faster    | materialize and sort all 32,768 IDs                    | algorithmic comparison | [Sorted-merge timings](/benchmarks/#sorted-merge)                                                                                             |
| Build a queue and update all 1,000 keys, 272× faster | `heap-js` linear remove plus push                      | algorithmic comparison | [Priority-queue timings](/benchmarks/#priority-queue)                                                                                         |
| Build 100,000 singleton sets, 164× faster            | a `Map` of `Set`s                                      | algorithmic comparison | [Disjoint-set timings](/benchmarks/#disjoint-set)                                                                                             |
| p-values agree with SciPy 1.15.3 to `1e-9`           | SciPy’s published reference values, pinned as fixtures | statistical parity     | [`__tests__/fixtures/PROVENANCE.md`](https://github.com/jkomyno/knotkit/blob/main/packages/hypothesis-test/__tests__/fixtures/PROVENANCE.md)  |
| 25 TLA+ models replay against the implementations    | each package’s own implementation                      | model conformance      | [`verification/`](https://github.com/jkomyno/knotkit/tree/main/verification)                                                                  |
| 43 subpaths smoke-tested in `Bun.WebView`            | 33 modules plus 10 `/wire` entrypoints                 | browser compatibility  | [CI workflow](https://github.com/jkomyno/knotkit/blob/main/.github/workflows/ci.yaml)                                                         |
| 39.1% lower latency, toy target, zero-cost draft     | target-only decoding; Qwen 0.5B draft: 37.4% slower    | research result        | [`problems/speculative-decoding/docs/RESULTS.md`](https://github.com/jkomyno/knotkit/blob/main/problems/speculative-decoding/docs/RESULTS.md) |

Read each ratio in the context of its workload

These ratios capture differences in the work each implementation does. The [benchmark gallery](https://github.com/jkomyno/knotkit/blob/main/evidence/benchmarks/README.md#reading-the-baselines) names every baseline and includes panels where native JavaScript wins.

## What the measurements cover

* **One machine, one runtime, one fixture.** The figures are historical. Each problem README records its machine, seed, and command; re-run the benchmark on your target hardware before making a runtime decision from one.
* **Microbenchmarks measure the whole workload invocation**, including construction where the panel says build, fill, or heapify. They do not measure your call site.
* **Accuracy figures are fixture-bound.** The MinHash banding result — 77 of 79,800 pairs scored, all 62 matches above the 0.6 Jaccard threshold recovered — is one pinned 400-document corpus, not a guarantee for another corpus.
* **Model replay checks bounded correctness.** The TLA+ models and implementation traces check invariants such as order and multiplicity on the states they cover.

## The interface-overhead study

`bun run bench:overhead` runs each caller workload twice: through Knotkit’s public API, and as a hand-written loop of the same algorithm. The ratio of the two medians is the interface overhead, the price of the abstraction rather than of the algorithm. Every panel is therefore audited `yes` or `no` for “same algorithm as the baseline”, and a `no` cell moves to a separate *Algorithm choice* section instead of being counted as overhead. The losses stay in. Its capture is local data: re-run the command to read the current numbers.

## Run the benchmarks yourself

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit
bun install
bun --bun run bench
```

The recorded timings are in [the benchmark explorer](/benchmarks/).

## Where the numbers live

| Artifact                                                                                                            | Content                                                    |
| ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| [`evidence/benchmarks/results.json`](https://github.com/jkomyno/knotkit/blob/main/evidence/benchmarks/results.json) | every row’s five within-run p50s, plus runtime and machine |
| [`evidence/benchmarks/README.md`](https://github.com/jkomyno/knotkit/blob/main/evidence/benchmarks/README.md)       | one section per panel, stating its baseline                |
| [`packages/*/__tests__/bench`](https://github.com/jkomyno/knotkit/tree/main/packages)                               | the suites, deterministic and re-runnable                  |
| [`problems/*/README.md`](https://github.com/jkomyno/knotkit/tree/main/problems)                                     | per-workload fixture, seed, command, and result            |
| [`verification/models`](https://github.com/jkomyno/knotkit/tree/main/verification/models)                           | the TLA+ models checked against the code                   |
