Skip to content

Documentation / spryte / gpuTimer

Function: gpuTimer() ​

gpuTimer(draw): GpuTimer

Defined in: gpu-timer.ts:47

Measure how long the GPU spends on what spryte draws, to tell whether a slow frame is GPU-bound (draw less, or smaller) or CPU-bound (simulate less). WebGL2 only, and only where the browser exposes EXT_disjoint_timer_query_webgl2: in practice Chromium on desktop; Safari, Firefox and Android Chrome don't.

ts
const gpu = gpuTimer(draw);
// each frame:
gpu.begin();
draw.begin("#000", w, h, dpr);
// ...draw...
draw.end();
gpu.end();
hud.text = gpu.ms === undefined ? "GPU: n/a" : `GPU ${gpu.ms.toFixed(1)} ms`;

Results arrive a few frames late and never block. Only one GPU timer can run at a time: inside another engine (createSharedRenderer) that already times its frame, or alongside a profiler, the frame is skipped.

Parameters ​

draw ​

Draw

Returns ​

GpuTimer