micro-fps

0.1.2 • Public • Published

micro-fps

Node NPM Travis David Coverage Status NPM

A super lightweight fps meter, with near zero overhead

createFpsMeter is a function factory, it returns a new meter.
But why not a class? Last time I checked, accessing instance properties was slower than accessing variables on a near closure.

Usage

JS fiddle Example: https://jsfiddle.net/Victornpb/g8pra2a6/

import microFps from 'micro-fps';
 
const REFRESH_RATE = 2; //update twice a second

const fpsTick = createFpsMeter(info=>{
    fps_div.innerHTML = info.fps.toFixed(2);
    console.log(info);
}, REFRESH_RATE);

Then call the returned function on every frame of your loop

//game loop
setInterval(function loop(){
    fpsTick();
    
    //do stuff

}, 1000/60);

Callback info object

property type description
fps float The calculated frames per second
jitter float The absolute difference since the last calculated fps
elapsed float Milliseconds ellapsed since the last computation
frames integer Number of frames since the last computation
trigger float Next computation will happen at this amount of frames

Installation

Install via yarn

yarn add micro-fps (--dev)

or npm

npm install micro-fps (--save-dev)

configuration

You can pass in extra options as a configuration object (➕ required, ➖ optional, ✏️ default).

import microFps from 'micro-fps';
 

property ( type ) ✏️ default
📝 description
❗️ warning
ℹ️ info
💡 example

methods

#name

microFps
 

Examples

See example folder or the runkit example.

Builds

If you don't use a package manager, you can access micro-fps via unpkg (CDN), download the source, or point your package manager to the url.

micro-fps is compiled as a collection of CommonJS modules & [ES2015 modules](http://www.2ality.com/2014/0 -9/es6-modules-final.html) for bundlers that support the jsnext:main or module field in package.json (Rollup, Webpack 2)

The micro-fps package includes precompiled production and development UMD builds in the dist/umd folder. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a <script> tag on your page. The UMD builds make micro-fps available as a window.microFps global variable.

License

The code is available under the MIT license.

Contributing

We are open to contributions, see CONTRIBUTING.md for more info.

Misc

This module was created using generator-module-boilerplate.

Readme

Keywords

none

Package Sidebar

Install

npm i micro-fps

Weekly Downloads

14

Version

0.1.2

License

MIT

Unpacked Size

22 kB

Total Files

8

Last publish

Collaborators

  • vitim