Macaw.Frame.Benchmark (macaw_frame v0.1.0)

Copy Markdown View Source

The benchmark harness (spec/12 §6), the core of visualize's Visualize.Benchmark: what the gates count, measured in time and bytes, so a person can see the trade between targets. It reads a clock only through its clock: option, so a fake clock makes it deterministic (visualize D-39).

run/1 times a fixture's render per target after 10 untimed warm-up renders:

OptionDefaultMeaning
:fixture"line"a fixture's name, a frame document with its deliveries, or a function (rows, {w, h}, frame) -> scene
:rows500rows per render, drawn from the fixture's generator
:iterations100timed renders per target
:size{800, 600}the frame's size
:targetsthe registered ones of [:svg, :canvas, :binary, :incremental]the targets measured
:clockfn -> System.monotonic_time(:microsecond) enda zero-arity monotonic clock in microseconds

Its result is config, then per target %{avg_us, renders_per_second, avg_bytes, total_ms, reductions} (reductions one render's count in a fresh process), and comparison: each target's time as a ratio of SVG's (of the first target's when SVG is not measured) rounded to two places, the fastest and the smallest per frame. Only the targets Macaw.Draw.Render.targets/0 registers can be measured; the canvas targets join with the Frame's live mode.

The fixtures (spec/12 §1.3) are the Frame's own, by name (Macaw.Frame.Fixtures.frame/0: "line", "bar", "scatter", …; the catalogs' fixtures join them with the catalogs), or a frame document with its deliveries: a map of settings (%{"design" => document}), deliveries, bindings and schemas, as a fixture holds them. Either is drawn by the Frame (Macaw.Frame.Value.init/3 and a delivery per slot, in :socketless at :size), and the scene it draws is what each target writes. Its generator makes :rows rows per slot from the slot's delivered rows taken in turn, each pass's times moved on by the rows' span, so the time fields keep rising; a stream's frame n moves them n steps on.

stream/1 renders frames for :duration_ms (5000) per target and answers per target %{frames, fps, rows_per_second, total_bytes, actual_ms}, fps = frames / max(actual_ms / 1000, 0.001). The loop reads the clock once at the start and once per iteration, rendering while the reading is under start + duration_ms; nothing but clock readings enters the elapsed time.

format/1 answers fixed-width sections, one per target, then the comparison. A bad option is a fault by its key, never a raise.

Summary

Types

A refusal: faults with their paths.

One target's timed renders.

run/1's answer: its configuration, a measure per target and the comparison.

One target's streamed frames.

stream/1's answer: its configuration and a measure per target.

Functions

A result of run/1 or stream/1 as fixed-width text.

Times a fixture's render per target: {:ok, result} or {:error, faults}.

Renders frames per target for a fixed duration: {:ok, stream_result} or {:error, faults}.

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

measure()

@type measure() :: %{
  avg_us: float(),
  renders_per_second: float(),
  avg_bytes: float(),
  total_ms: float(),
  reductions: non_neg_integer()
}

One target's timed renders.

result()

@type result() :: %{
  :config => map(),
  :comparison => map(),
  optional(atom()) => measure()
}

run/1's answer: its configuration, a measure per target and the comparison.

stream_measure()

@type stream_measure() :: %{
  frames: non_neg_integer(),
  fps: float(),
  rows_per_second: float(),
  total_bytes: non_neg_integer(),
  actual_ms: float()
}

One target's streamed frames.

stream_result()

@type stream_result() :: %{:config => map(), optional(atom()) => stream_measure()}

stream/1's answer: its configuration and a measure per target.

Functions

format(result)

@spec format(result() | stream_result()) :: String.t() | error()

A result of run/1 or stream/1 as fixed-width text.

run(opts \\ [])

@spec run(keyword()) :: {:ok, result()} | error()

Times a fixture's render per target: {:ok, result} or {:error, faults}.

stream(opts \\ [])

@spec stream(keyword()) :: {:ok, stream_result()} | error()

Renders frames per target for a fixed duration: {:ok, stream_result} or {:error, faults}.