Giter Club home page Giter Club logo

performance-plus's Introduction

Performance Plus

This is a utility and convenience library for the browser-based performance API, with support for IE8+ and zero dependencies.

The performance API allows for sub-millisecond, high-resolution timestamp measurements. This library adds some basic statistical helpers while collecting that data in slightly better style. In browsers below Internet Explorer 10, the performance API is unsupported. This library pseudo-fills that hole with plain old objects to deliver the same interface, just not at sub-millisecond resolution.

Example Usage

import perf from 'performance-plus';

var action = 'foobar';
perf.start(action);     // capture start timestamp
func();                 // this thing takes some time
perf.end(action);       // capture ending timestamp
// repeat the above loop a few times

console.log(`[perf] action ${action}`,
    `took ${perf.duration(action).toFixed(2)}ms`, {
    mean:         perf.mean(action),
    sdev:         perf.sdev(action),
    sampleSize:   perf.getEntriesByName(action).length,
    '95th_perc':  perf.percentile(action, 0.95)
});
// It can also measure FPS rendering
perf.onFPS((fps, time) => {
    console.log(`It is now ${time} and we are rendering at ${fps} frames per second`);
}, 2000); // measure and call every 2 seconds

Installation

$ npm install performance-plus --save

Methods

Commonly used methods:

perf.now();                     // high-res timestamp
perf.start('something');
perf.end('something');
perf.duration('something');     // in ms
perf.mean('something');         // in ms
perf.sdev('something');         // in ms
perf.getEntriesByName('something'); // all measures for this name
perf.getEntryByName('something');   // last measure for this name

Complete methods with JSDocs

Acknowledgements

performance-plus's People

Contributors

joshbeckman avatar

Stargazers

 avatar

Watchers

 avatar

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.