Socket
Book a DemoInstallSign in
Socket

fps-calculation

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fps-calculation

A simple api used for calculating the FPS or function call per second.

0.0.3
latest
Source
npmnpm
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

FPS calculation

A simple api used for calculate the FPS or function call per second when doing loop jobs.

Installation

npm install fps-calculation --save
# or
yarn add fps-calculation

Usage

/**
 * calculate the fps or function call per sec.
 * @param {function} cb primary function
 * @param {object} context function context
 * @param {boolean} enableConsole log the current FPS
 */
function calcFrames(cb, context, enableConsole = false) {}
import { calcFrames } from "fps-calculation";

// Assume this is a loop call engine
// when call the start method
// cb will be called at every requestAnimationFrame hook
const engine = {
  start(cb) {},
};

// Assume this is a loop function
function cb() {
  // ...
  // Get current FPS
  const currentFps = cb.__frames__;
  // ...
}

// Wrap the function and then return a closure
const wrapCb = calcFrames(cb, this, true);
engine.start(wrapCb);

// Hook function registration below is optional

// Register a callback when refreshing (end of a function call)
cb.__onRefresh__ = function () {
  console.log("End of the function call");
};

// Register a callback when FPS change (end of a function call)
cb.__onFPSChange__ = function (curFPS, prevFPS) {
  console.log("FPS changed from " + prevFPS + " to" + curFPS);
};

License

MIT

Keywords

fps

FAQs

Package last updated on 27 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.