Skip to content

Measure and display FPS for a Mapbox GL JS map

License

Notifications You must be signed in to change notification settings

therobwatson/mapbox-gl-fps

 
 

Repository files navigation

Mapbox GL FPS

A frames-per-seconds measurer and GUI control

Example of GUI FPS counter and report data

Classes

  • class FPSMeasurer - An non-dependent class for measuring FPS and calculating stats.
  • class FPSControl - A MapBox GL GUI Control

Example with GUI Control

var fpsControl = new MapboxFPS.FPSControl();
myMap.addControl(fpsControl, 'top-right');

setTimeout(function(){
    var report = fpsControl.measurer.getMeasurementsReport();
    console.log('Report:', report);
}, 10000)

Example with standalone class

var fpsMeasurer = new MapboxFPS.FPSMeasurer();

fpsMeasurer.startMeasuring();

// Measure 'mock render frames' every 20 ms for 2 seconds
var interval = setInterval( () => { measurer.registerRenderFrame() }, 20);

setTimeout( () => {
  // Stop the mock frame render interval
  clearInterval(interval);

  // Stop measuring
  fpsMeasurer.startMeasuring();

  // Generate report
  var report = measurer.getMeasurementsReport();
  console.log('Report: ', report);

}, 2000);

Generate Report

var fpsMeasurer = new MapboxFPS.FPSMeasurer();
var report = measurer.getMeasurementsReport();

returns an object:

// generated report
{
  "measurements": [...], // Array of actual measurements done
  "median": Number,
  "average": Number,
  "variance": Number,
  "stdDev": Number
}

About

Measure and display FPS for a Mapbox GL JS map

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 81.5%
  • HTML 18.5%