# Benchmarks

<!-- Generated by scripts/gen-benchmarks-md.mjs from the files of a `umis bench` run. Do not edit by hand. -->

How long a verifier takes to decide, measured with `umis bench` on the demo world: 1000 different presentations in each
of 30 repeats per scenario, after 1 warm-up repeat thrown away, with a new replay store in every repeat. Only the call
that decides is timed; the presentations are made before the timing starts. Milliseconds; the figures belong to the
machine below and to this run.

The figures are decision latencies inside one Node process with synthetic inputs: they exclude the camera, the optical
decoding of the QR code, the radio and the network.

## Environment

| Run         | Commit    | Node     | System       | CPU                    | Memory (bytes) |
| ----------- | --------- | -------- | ------------ | ---------------------- | -------------- |
| `webcrypto` | `9fae286` | v24.19.0 | Darwin arm64 | Apple M1 Pro, 10 cores | 34359738368    |
| `noble`     | `9fae286` | v24.19.0 | Darwin arm64 | Apple M1 Pro, 10 cores | 34359738368    |

Reproduce a run from the root of a clone, after `pnpm install && pnpm build`, on a machine that is otherwise idle:

```sh
node packages/cli/dist/bin.js bench --scenario all --n 1000 --repeats 30 --warmup 1 --crypto webcrypto --seed umis --out bench-results/webcrypto
node packages/cli/dist/bin.js bench --scenario all --n 1000 --repeats 30 --warmup 1 --crypto noble --seed umis --out bench-results/noble
node scripts/gen-benchmarks-md.mjs bench-results/webcrypto bench-results/noble
```

## Decision latency, `webcrypto`

| Scenario      | Expected                   |   P50 |   P95 | P95 REP |       P95 CI95 |    P99 |  Mean |    SD |     Max | QR chars (p50 / max) | Mismatches | NFR-P1 |
| ------------- | -------------------------- | ----: | ----: | ------: | -------------: | -----: | ----: | ----: | ------: | -------------------: | ---------: | ------ |
| `oneway-low`  | accept                     | 0.313 | 0.542 |   0.539 | 0.491 .. 0.587 |  1.366 | 0.365 | 0.203 |   8.496 |            350 / 353 |          0 | met    |
| `full-qr-low` | accept                     | 0.574 | 1.950 |   1.991 | 1.877 .. 2.105 |  3.070 | 0.769 | 0.704 |  29.126 |          1301 / 1319 |          0 | met    |
| `s1-accept`   | accept                     | 0.618 | 2.164 |   2.230 | 2.105 .. 2.355 |  3.307 | 0.859 | 0.801 |  37.113 |          1750 / 1765 |          0 | met    |
| `s1-reject`   | `AUTHORITY_LIMIT_EXCEEDED` | 0.732 | 2.369 |   2.433 | 2.298 .. 2.568 |  3.856 | 0.964 | 0.787 |  16.630 |          1823 / 1838 |          0 | met    |
| `mutual`      | accept                     | 1.261 | 3.152 |   3.230 | 2.821 .. 3.639 |  5.455 | 1.530 | 1.069 |  36.974 |          1414 / 1930 |          0 | met    |
| `oid4vp`      | accept                     | 0.481 | 0.737 |   0.736 | 0.718 .. 0.755 |  1.691 | 0.523 | 0.217 |   8.724 |            779 / 779 |          0 | met    |
| `gateway`     | accept                     | 2.361 | 4.760 |   4.648 | 3.165 .. 6.131 | 11.571 | 2.791 | 2.289 | 100.243 |            350 / 353 |          0 | met    |

## Decision latency, `noble`

| Scenario      | Expected                   |    P50 |    P95 | P95 REP |         P95 CI95 |    P99 |   Mean |    SD |     Max | QR chars (p50 / max) | Mismatches | NFR-P1 |
| ------------- | -------------------------- | -----: | -----: | ------: | ---------------: | -----: | -----: | ----: | ------: | -------------------: | ---------: | ------ |
| `oneway-low`  | accept                     |  3.471 |  3.932 |   4.364 |   3.305 .. 5.421 |  6.280 |  3.637 | 1.484 |  86.026 |            350 / 352 |          0 | met    |
| `full-qr-low` | accept                     |  5.589 |  6.198 |   6.668 |   5.738 .. 7.599 |  8.667 |  5.740 | 1.583 |  73.941 |          1304 / 1319 |          0 | met    |
| `s1-accept`   | accept                     |  5.622 |  6.561 |   6.916 |   6.011 .. 7.820 |  9.824 |  5.829 | 1.841 |  77.429 |          1745 / 1763 |          0 | met    |
| `s1-reject`   | `AUTHORITY_LIMIT_EXCEEDED` |  5.586 |  6.275 |   7.296 |   4.979 .. 9.613 | 10.719 |  5.862 | 2.924 | 135.525 |          1822 / 1838 |          0 | met    |
| `mutual`      | accept                     | 12.338 | 13.981 |  14.498 | 13.316 .. 15.680 | 21.188 | 12.681 | 2.547 | 141.861 |          1418 / 1928 |          0 | met    |
| `oid4vp`      | accept                     |  5.040 |  5.529 |   5.495 |   5.395 .. 5.595 |  6.226 |  5.116 | 0.382 |  21.215 |            779 / 779 |          0 | met    |
| `gateway`     | accept                     |  5.826 |  7.035 |   7.372 |   6.395 .. 8.349 | 10.865 |  6.020 | 1.571 |  82.928 |            350 / 352 |          0 | met    |

P50, P95 and P99 are nearest-rank percentiles of all measured decisions of a scenario. P95 CI95 is the Student-t 95 %
interval of the mean of the per-repeat P95 values, so the pooled P95 can lie slightly outside it. NFR-P1 is met when the
P95 is within one second. QR chars are the characters of the QR texts that the size table below marks as counted; the
`mutual` row pools the init and the reply texts of the exchange, which the size table shows apart. A mismatch is a
presentation decided otherwise than the scenario expects.

- `mutual`: both decisions of the exchange, timed together.
- `oid4vp`: the provider's decision only; the wallet's part and the HTTP round trip are excluded.
- `gateway`: the decision plus a signed relay command against a loopback emulator; connection set-up is excluded.

`webcrypto` is the WebCrypto of Node; `noble` is the JavaScript implementation that stands in for the engine of Expo Go.
The seed (`umis`) fixes keys, identifiers and salts; WebCrypto signatures stay random, so a WebCrypto run is not
reproducible bit for bit.

## QR text sizes, `webcrypto`

| Scenario      | Text               | Counted | Count |  Min |  P50 |  Max |
| ------------- | ------------------ | ------- | ----: | ---: | ---: | ---: |
| `oneway-low`  | `qr_oneway`        | yes     | 30000 |  344 |  350 |  353 |
| `full-qr-low` | `qr_full`          | yes     | 30000 | 1282 | 1301 | 1319 |
| `s1-accept`   | `qr_request`       | no      | 30000 |  620 |  643 |  661 |
| `s1-accept`   | `qr_response`      | yes     | 30000 | 1730 | 1750 | 1765 |
| `s1-reject`   | `qr_request`       | no      | 30000 |  620 |  643 |  662 |
| `s1-reject`   | `qr_response`      | yes     | 30000 | 1802 | 1823 | 1838 |
| `mutual`      | `qr_mutual_init`   | yes     | 30000 | 1889 | 1913 | 1930 |
| `mutual`      | `qr_mutual_reply`  | yes     | 30000 | 1379 | 1397 | 1414 |
| `oid4vp`      | `qr_login_request` | yes     | 30000 |  779 |  779 |  779 |
| `oid4vp`      | `post_body`        | no      | 30000 | 1596 | 1596 | 1596 |
| `gateway`     | `qr_oneway`        | yes     | 30000 |  343 |  350 |  353 |

## Autonomy and revocation

Played on a simulated clock (`webcrypto` run):

- Autonomy, `low` (`door_low`): 961 presentations over 80 h, one every 300 s; accepted up to S = 259200 s (last accept
  at 259200 s), `STATUS_LIST_STALE` from 259201 s: exactly at S + 1 s.
- Autonomy, `medium` (`warehouse_medium`): 361 presentations over 30 h, one every 300 s; accepted up to S = 86400 s
  (last accept at 86400 s), `STATUS_LIST_STALE` from 86401 s: exactly at S + 1 s.
- Revocation of a credential at 1 s: refused online 599 s later (bound Δ = 600 s, refresh every 600 s) and offline 86400
  s later (bound min(T; S) = 86400 s): within the bounds.

The limits of these figures are listed in [known limitations](limitations.md#benchmarks).
