Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 974 Bytes

File metadata and controls

39 lines (28 loc) · 974 Bytes

@dimensionalpocket/fps

build

Frames-per-second counter for Javascript.

Usage

import Fps from '@dimensionalpocket/fps'

// Initialize a counter with a given sample size in frames.
// Default sample size is 60 (1 second).
// Larger sizes affect average calculations.
const fps = new Fps(300) // 5 seconds

// Synchronous usage (no await):
fps.start()
// ... your code
fps.stop()

// Synchronous or asynchronous:
var startAt = fps.now()
// ... your code
fps.add(fps.now() - startAt)

// Returns the average FPS
fps.average()

// Usage with reactive libs
fps.total            // returns the sum of all given values
fps.size             // the sample count
fps.total / fps.size // the average value
fps.max              // the largest value (resets every 10 iterations)

License

MIT