Skip to main content

createBenchmark

function createBenchmark(clock, options): Benchmark;

Creates a benchmarking utility for measuring frame durations and calculating frames per second (FPS).

Parameters

ParameterTypeDefault valueDescription
clockClockperformanceAn object with a now() method returning the current timestamp (in milliseconds). Defaults to window.performance.
optionsBenchmarkOptions{}Optional configuration options for the benchmark utility.

Returns

Benchmark

An object with methods to start/end frame measurements, reset the benchmark, and calculate current FPS.

Remarks

This function is designed for performance measurement in animation or game loops. It records frame start/end times, ignores an initial warmup period, utilizes a circular buffer to average recent frame durations, and computes a smoothed FPS value on demand. The calculation may only occur if sufficient samples have been gathered and the minimum interval between calculations has elapsed.