Visualize.Benchmark (Visualize v0.2.35)

Copy Markdown View Source

Performance benchmarking utilities for comparing rendering backends.

Measures throughput and payload sizes across SVG, Canvas, Hybrid, and Canvas-Incremental backends.

Example

# Run a quick benchmark
results = Visualize.Benchmark.run(data_points: 1000, iterations: 100)

# Results include svg, canvas, hybrid, and incremental measurements
IO.puts(Visualize.Benchmark.format_report(results))

Hybrid Mode

Hybrid mode simulates the pattern where static elements (axes, labels) are rendered once as SVG, and only the dynamic data is sent each frame as Canvas commands. This measures the "per-frame" cost for real-time updates.

Hybrid-Incremental Mode

Hybrid-Incremental combines the Hybrid approach (static SVG axes) with incremental scroll optimization for the data layer. Only newly exposed data regions are sent each frame.

Canvas-Incremental Mode

Canvas-Incremental renders the full chart to Canvas with incremental scroll optimization. Copies existing canvas content shifted and only renders newly exposed regions. Best for time-series visualizations with continuous scrolling.

Summary

Functions

Formats benchmark results as a human-readable report.

Formats streaming benchmark results.

Runs a benchmark comparing SVG, Canvas, Hybrid, Hybrid-Incremental, and Canvas-Incremental backends.

Runs a streaming benchmark simulating real-time data updates.

Functions

format_report(results)

@spec format_report(map()) :: String.t()

Formats benchmark results as a human-readable report.

format_stream_report(results)

@spec format_stream_report(map()) :: String.t()

Formats streaming benchmark results.

run(opts \\ [])

@spec run(keyword()) :: map()

Runs a benchmark comparing SVG, Canvas, Hybrid, Hybrid-Incremental, and Canvas-Incremental backends.

Options

  • :data_points - Number of data points per render (default: 500)
  • :iterations - Number of render iterations (default: 100)
  • :chart_type - Type of chart to benchmark: :line, :area, :scatter (default: :line)
  • :width - Chart width (default: 800)
  • :height - Chart height (default: 600)

stream_benchmark(opts \\ [])

@spec stream_benchmark(keyword()) :: map()

Runs a streaming benchmark simulating real-time data updates.

Returns statistics about how many frames per second each backend can achieve.

Options

  • :duration_ms - How long to run the benchmark (default: 5000)
  • :data_points - Points per frame (default: 200)
  • :chart_type - Chart type (default: :line)
  • :width - Chart width (default: 800)
  • :height - Chart height (default: 600)
  • :clock - A zero-arity function returning milliseconds on a monotonic clock (default: System.monotonic_time(:millisecond)); every frame count and elapsed time is read from it, so a fake clock makes the benchmark deterministic (D-39)