createBenchmark
function createBenchmark(clock, options): Benchmark;
Creates a benchmarking utility for measuring frame durations and calculating frames per second (FPS).
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
clock | Clock | performance | An object with a now() method returning the current timestamp (in milliseconds). Defaults to window.performance. |
options | BenchmarkOptions | {} | Optional configuration options for the benchmark utility. |
Returns
An object with methods to start/end frame measurements, reset the benchmark, and get current FPS.
Remarks
Uses a time-windowed sliding approach: each frame event stores both its timestamp and
processing duration. Only events within the configured time window contribute to FPS.
FPS is derived as windowMs / averageProcessingTime for events in the window.
The begin()/end() API measures processing time per frame explicitly.
Call fps() at any time to get the current FPS — no priming or two-call pattern needed.