All Projects → dmnsgn → raf-perf

dmnsgn / raf-perf

Licence: MIT License
RAF loop with an adaptive fps and performance ratio calculated from either a sample count or a sample duration. Typically used when doing intensive graphics computation in canvas.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to raf-perf

raf-interval
setRafInterval and clearRafInterval with requestAnimationFrame - 40行代码实现的高性能动画定时器
Stars: ✭ 77 (+92.5%)
Mutual labels:  requestanimationframe, ticker, tick
animate
👾 Create and manage animation functions with AnimationFrame API.
Stars: ✭ 11 (-72.5%)
Mutual labels:  loop, requestanimationframe
anim-event
Event Manager for Animation
Stars: ✭ 25 (-37.5%)
Mutual labels:  throttle, requestanimationframe
slotjs
🎰 Circular slot machine mobile-first SPA built using JavaScript, CSS variables and Emojis!
Stars: ✭ 90 (+125%)
Mutual labels:  requestanimationframe
advanced-post-list
A WordPress plugin to create custom post lists
Stars: ✭ 15 (-62.5%)
Mutual labels:  loop
node-red-contrib-actionflows
Provides a set of nodes to enable an extendable design pattern for flows.
Stars: ✭ 38 (-5%)
Mutual labels:  loop
barbar
DEPRECATED — OSX crypto-currency price ticker
Stars: ✭ 55 (+37.5%)
Mutual labels:  ticker
FWDebug
iOS调试库,支持iOS11+,无需添加任何代码,方便iOS开发和测试。 iOS debugging library, support for iOS11 +, without adding any code to facilitate iOS development and testing.
Stars: ✭ 49 (+22.5%)
Mutual labels:  fps
ebs snapper
Next generation AWS tool for EBS snapshots using Lambda
Stars: ✭ 51 (+27.5%)
Mutual labels:  fps
Frame-Number-Sync
Keeps time in sync between server and client.
Stars: ✭ 31 (-22.5%)
Mutual labels:  tick
nativescript-performance-monitor
⚡ Proof your app maintains 60-ish FPS by collecting data or showing it on screen with this NativeScript plugin!
Stars: ✭ 21 (-47.5%)
Mutual labels:  fps
nordnet
Uonfficial wrapper for financial data api from the Scandinavian broker Nordnet
Stars: ✭ 13 (-67.5%)
Mutual labels:  tick
debounced-notifications
Basecamp style notification debouncing / throttling for Laravel notifications.
Stars: ✭ 30 (-25%)
Mutual labels:  throttle
use-elapsed-time
React hook to measure elapsed time using requestAnimationFrame
Stars: ✭ 42 (+5%)
Mutual labels:  requestanimationframe
stiff3
Adaptive solver for stiff systems of ODEs using semi-implicit Runge-Kutta method of third order
Stars: ✭ 13 (-67.5%)
Mutual labels:  adaptive
HTML-Crypto-Currency-Chart-Snippets
💹 Simple HTML Snippets to create Tickers / Charts of Cryptocurrencies with the TradingView API 💹
Stars: ✭ 89 (+122.5%)
Mutual labels:  ticker
react-fps-stats
Graphics Performance Monitor for React
Stars: ✭ 21 (-47.5%)
Mutual labels:  fps
coinbash
💰 A bash script (CLI) for displaying crypto currencies market data in a terminal 🖥
Stars: ✭ 110 (+175%)
Mutual labels:  ticker
ameshref
Efficient Matlab Implementation of Adaptive Mesh Refinement in 2D
Stars: ✭ 28 (-30%)
Mutual labels:  adaptive
ProcessingStuff
Various pretty-ish Processing sketches by Odditica. About 50% shaders.
Stars: ✭ 164 (+310%)
Mutual labels:  loop

raf-perf

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

RAF loop with an adaptive fps and performance ratio calculated from either a sample count or a sample duration. Typically used when doing intensive graphics computation in canvas.

paypal coinbase twitter

Installation

npm install raf-perf

Usage

import RafPerf from "raf-perf";
import createCanvasContext from "canvas-context";

const { context, canvas } = createCanvasContext("2d", {
  width: window.innerWidth,
  height: window.innerHeight,
  offscreen: true,
});
document.body.appendChild(canvas);

const engine = new RafPerf();

engine.on("tick", (dt) => {
  // Clear
  context.clearRect(0, 0, canvas.width, canvas.height);

  // Draw
  // ...
});

engine.on("perf", (ratio) => {
  if (!ratio) return;

  console.log(`Performance ratio: ${ratio}`);

  if (ratio < 0.9) {
    console.log("Too many draws");
  } else if (ratio >= 0.9 && rectCount < maxRectCount) {
    console.log("Draw more");
  }
});

engine.start();

const destroy = () => {
  if (engine.isRunning) engine.stop();
  engine.removeAllListeners("tick");
  engine.removeAllListeners("perf");
};

API

Classes

RafPerf

Typedefs

Options : Object
OptionsPerformances : Object

RafPerf

Kind: global class

new RafPerf([options])

Creates an instance of RafPerf.

Param Type Default Description
[options] Options {} samplesCount and sampleDuration are used concurrently. Set sampleDuration to a falsy value if you only want to sample performances from a number of frames.

rafPerf.start()

Run the requestAnimationFrame loop and start checking performances if options.performances.enabled is true.

Kind: instance method of RafPerf

rafPerf.tick()

The frame loop callback.

Kind: instance method of RafPerf
Emits: perf, tick

rafPerf.stop()

Run cancelAnimationFrame if necessary and reset the engine.

Kind: instance method of RafPerf

"perf"

Event triggered when performance ratio (this.frameDuration / averageDeltaTime) is updated. Understand a ratio of the fps, for instance for a fps value of 24, ratio < 0.5 means that the averaged fps < 12 and you should probably do something about it.

Kind: event emitted by RafPerf

"tick"

Event triggered on tick, throttled by options.fps.

Kind: event emitted by RafPerf

Options : Object

Kind: global typedef
Properties

Name Type Default Description
[fps] number 60 Throttle fps.
[performances] OptionsPerformances { enabled: true, samplesCount: 200, sampleDuration: 4000 } Performances metrics.

OptionsPerformances : Object

Kind: global typedef
Properties

Name Type Default Description
[enabled] boolean false Evaluate performances.
[samplesCount] number 200 Number of samples to evaluate performances.
[sampleDuration] number 200 Duration of sample to evaluate performances.

License

MIT. See license file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].