# `Macaw.Live.Bench`
[🔗](https://github.com/dcoai/macaw_live/blob/v0.1.0/lib/macaw/live/bench.ex#L1)

The benchmark harness behind the performance requirements (spec/07 §8), in the shape of
visualize's `Visualize.Benchmark`: `run/2` measures, `format/1` reports.

A scenario is a module with `name/0`, `setup/0` (the state each move is measured from)
and `measure/1` (one move of the scenario, answering its measurements:
`%{reductions: %{process => count}, bytes: diff_bytes, flat: %{crossing => words}}`).
`run/2` runs each scenario once to settle, then five times, and reports per measurement
the median and range, with the milliseconds of work each move took beside them.
**Milliseconds are reported, never asserted** (macaw spec/00 §4.4): the pinned bounds
live in the tests, in reductions, bytes and words, each beside the measurement it was set
from.

The scenarios join with the steps that own them (spec/07 §1–§7). They drive the
reference grid of the suite's support (`Macaw.Live.Test.Grid`), compiled in the test
environment, which `mix macaw_live.bench` runs in; elsewhere there are none.

# `measure`

```elixir
@callback measure(state :: term()) :: %{
  optional(:reductions) =&gt; %{required(term()) =&gt; non_neg_integer()},
  optional(:bytes) =&gt; non_neg_integer(),
  optional(:flat) =&gt; %{required(term()) =&gt; non_neg_integer()}
}
```

One move's measurements.

# `name`

```elixir
@callback name() :: String.t()
```

The scenario's name, as the report shows it.

# `setup`

```elixir
@callback setup() :: term()
```

The state each move is measured from.

# `format`

```elixir
@spec format([map()]) :: String.t()
```

The report `mix macaw_live.bench` prints: one block per scenario.

# `run`

```elixir
@spec run([module()], keyword()) :: [map()]
```

Each scenario measured (spec/07 §8): a settling run, then `runs:` (five) measured moves:
`[%{name:, runs:, reductions:, bytes:, flat:, ms:}]`, each measurement summarized as
`%{median:, min:, max:}`.

# `scenarios`

```elixir
@spec scenarios() :: [module()]
```

The scenarios `mix macaw_live.bench` runs by default: those compiled here.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
