Coder Social home page Coder Social logo

pstats.js's Introduction

pstats.js

Visualizing and monitor your performance.

Inspired by rStats.js.

pstats.js

Install

npm install pstats.js

Usage

let stats = pstats.new(document.body, {
  showGraph: true,
  values: {
    frame: { desc: 'Total frame time (ms)', over: 18, average: 100 },
    raf: { desc: 'Time since last rAF (ms)', average: 100 },
    fps: { desc: 'Framerate (FPS)', below: 30, average: 500 },
    render1: { desc: 'WebGL Render 01 (ms)' },
    render2: { desc: 'WebGL Render 02 (ms)' },
    user01: { desc: 'User Value 01 (ranged)', min: -1, max: 1, color: '#080' },
    user02: { desc: 'User Value 02 (threshold)', color: '#09f', threshold: true },
    memory: { desc: 'Memory', extension : 'memory.used', average: 1000, threshold: true },
  },
  fractions: [
    { base: 'frame', steps: ['render1', 'render2'] },
    { base: 'frame', steps: ['render1', 'render2'], colors: ['#09f', '#f90'] },
  ],
  extensions: [
    'memory'
  ],
});

function delay() {
  let d = Math.random() * 10;
  let now = Date.now();
  let s = now + d;
  while (now < s) {
    now = Date.now();
  }
}

let t = 0;

function render() {
  stats('frame').start();
    stats('memory').snapshot();
    stats('raf').tick();
    stats('fps').frame();

    stats('render1').start();
      delay();
    stats('render1').end();

    stats('render2').start();
      delay();
    stats('render2').end();

    stats('user01').value = Math.sin(t);
    stats('user02').value = Math.pow(t % 10, 3);
    t += 0.1;
  stats('frame').end();

  stats().tick();
  requestAnimationFrame(render);
}

render();

Documentation

TODO

License

MIT © 2017 Johnny Wu

pstats.js's People

Contributors

cyy641278529 avatar jwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cyy641278529

pstats.js's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.