npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fps-now

v3.1.1

Published

FPS meter for evergreen browsers

Downloads

465

Readme

fps-now

FPS meter for evergreen browsers

npm version Dependency Status js-standard-style

Install

Install with npm

$ npm i -S fps-now

Example

const FPS = require('fps-now')

var fps = FPS.of()
fps.start()

See example.js.

Usage

The FPS object is a convenient component for displaying the current fps of the browser it is running in. As it is tied specifically to the frame rate there is no option to manually control the tick, instead, the consumer calls fps.start() and forgets all about it.

Usage is kept deliberately as minimal as possible, to use you must create an instance of the FPS meter and then call start on it when you’re ready to start recording.

var fps = FPS.of()
fps.start()

There are a few options that can be passed to control the meter, again, the options are kept deliberately minimal.

const defaultOptions = {
  x: 64,
  y: 32,
  shape: [64, 32],
  visual: true,
  averageFPS: false
}

Sample size (shape)

x and y convert into [x, y], and are identical to shape, if shape is supplied as an option it will take precedence.

shape controls the sample size (x) and the height of the graph (y). As the FPS meter is decoupled from the render the y is largely irrelevant, although it is useful if you use the default rendering method.

The meter calculates the fps for each tick (based on the duration of the tick, with a little bit of estimation, full credit for the algorithm used goes to hughsk). This fps is stored in an array whose length is the sample size, the sample is a window on to the latest x frame rate readings.

A larger sample size will mean more accurate results, but also less performant. Generally speaking only a small sample size is required.

Rendering

fps-now comes bundles with a super-basic renderer, creating your own is fairly straight forward though. To turn off default rendering set {visual: false} when instantiating the meter.

The FPS object is an event emitter and will emit the current fps samples, allowing you to create your own renderer on top.

For example, if you just wanted to display last tick frame rate something like the following would work:

var el = document.createElement('div')
document.body.appendChild(el)

var fps = FPS.of({
  visual: false
})
fps.on('tick', function onTick (graph) {
  el.innerHTML = graph[graph.length - 1].toFixed(1)
})

fps.start()

There is another use-case for setting visual: false which is if you just want to measure FPS and maybe make decisions in your application based on that. Visualisation is unnecessary for this. You can use the emitted tick event to access the frame rate history and do whatever you need with that record of history.

Averaging

By default only the last ticks frame rate is rendered, set {averageFPS: true} if you want an average of the samples.

This is slightly heavier performance-wise but smoothes out fluctuations in frame rate.

Generally speaking, usually the last tick frame rate is sufficient for monitoring fluctuations in the frame rate.

Running tests

$ npm install
$ npm test

Contributing

Pull requests are always welcome, the project uses the standard code style. Please run npm test to ensure all tests are passing and add tests for any new features or updates.

For bugs and feature requests, please create an issue.

License

MIT