# `DalaDev.Benchmark`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/dala_dev/benchmark.ex#L1)

Runtime benchmarking for dala Elixir nodes.

Measure execution time, memory usage, reductions, and compare
performance across different devices in the cluster.

## Examples

    # Measure a function on a remote node
    {:ok, result, stats} = DalaDev.Benchmark.measure(
      :"dala_qa@192.168.1.5",
      fn -> MyApp.heavy_computation() end
    )

    # Compare performance across nodes
    DalaDev.Benchmark.compare([node1, node2], test_module: MyBench)

    # Profile memory usage
    DalaDev.Benchmark.memory_profile(node, duration: 60_000)

# `benchmark_result`

```elixir
@type benchmark_result() :: %{
  node: node(),
  wall_time: integer(),
  reductions: integer(),
  memory: integer(),
  process_count: integer(),
  message_queue_len: integer()
}
```

# `node_ref`

```elixir
@type node_ref() :: node() | DalaDev.Device.t() | :all_nodes
```

# `compare`

```elixir
@spec compare(
  [node_ref()],
  keyword()
) :: [benchmark_result()]
```

Compare performance across multiple nodes.

Options:
- `:test_module` - Module containing benchmark functions
- `:test_function` - Function to call (default: :run/0)
- `:iterations` - Number of iterations per node

Returns a list of benchmark results for comparison.

# `measure`

```elixir
@spec measure(node_ref(), (-&gt; any()), keyword()) ::
  {:ok, any(), benchmark_result()} | {:error, term()}
```

Measure execution time and resource usage of a function on a remote node.

Options:
- `:timeout` - RPC timeout in ms (default: 30_000)
- `:warmup` - Number of warmup iterations (default: 1)
- `:iterations` - Number of measurement iterations (default: 1)

Returns `{:ok, result, stats}` or `{:error, reason}`.

# `memory_profile`

```elixir
@spec memory_profile(
  node_ref(),
  keyword()
) :: {:ok, [map()]} | {:error, term()}
```

Profile memory usage on a node over time.

Options:
- `:duration` - Profile duration in ms (default: 60_000)
- `:interval` - Sampling interval in ms (default: 1_000)

Returns memory statistics over time.

# `report`

```elixir
@spec report(
  [benchmark_result()],
  keyword()
) :: {:ok, String.t() | :ok} | {:error, term()}
```

Generate a benchmark report.

Options:
- `:format` - :text (default), :html, or :json
- `:output` - Output file path (optional)

Returns the report content or :ok if saved to file.

---

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