Stats.js Performance Monitor

0.17.0 · active · verified Sun Apr 19

Stats.js is a lightweight, client-side JavaScript performance monitor designed to display real-time metrics such as Frames Per Second (FPS), milliseconds per frame (MS), and allocated memory (MB) directly in the browser. The current stable version, 0.17.0 (r17), introduced a significant change by converting the library to an ECMAScript module. While its release cadence has historically been irregular, with key updates like `r16` adding `devicePixelRatio` support and `r15` reverting to a more efficient canvas-based rendering, `r17` represents the most recent major shift in its distribution format. It differentiates itself through its minimal footprint and immediate visual feedback, making it an excellent tool for quick performance profiling during development without requiring complex tooling integrations.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize Stats.js, append it to the document body, and integrate it into an animation loop to monitor performance metrics like FPS.

import Stats from 'stats.js';

const stats = new Stats();
stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
stats.dom.style.position = 'fixed';
stats.dom.style.top = '0px';
stats.dom.style.left = '0px';
stats.dom.style.zIndex = '10000';
document.body.appendChild( stats.dom );

function animate() {
  stats.begin();

  // Your monitored code goes here
  // For example, a simple loop or animation logic
  for (let i = 0; i < 100000; i++) {
    Math.sin(i);
  }

  stats.end();

  requestAnimationFrame( animate );
}

requestAnimationFrame( animate );

view raw JSON →