Skip to content

Instantly share code, notes, and snippets.

@ivancuric
Created March 27, 2017 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancuric/5ac6fd635c6d82a5f8d5884fe21a7911 to your computer and use it in GitHub Desktop.
Save ivancuric/5ac6fd635c6d82a5f8d5884fe21a7911 to your computer and use it in GitHub Desktop.
Method for finding out the refresh rate of the device
function _getRefreshRate() {
const rafPromise = _ => new Promise(requestAnimationFrame);
const idlePromise = _ => new Promise(requestIdleCallback);
let f1, f2;
return new Promise(resolve => {
idlePromise()
.then(_ => rafPromise())
.then(frame => {f1 = frame; return rafPromise();})
.then(frame => {f2 = frame; return rafPromise();})
.then(_ => {
const ft = f2 - f1;
const fps = Math.ceil(1000 / ft);
console.log(`Refresh rate should be ${fps}Hz`);
resolve();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment