Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created March 18, 2015 14:57
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 gkucmierz/151b27561e0f3c45e016 to your computer and use it in GitHub Desktop.
Save gkucmierz/151b27561e0f3c45e016 to your computer and use it in GitHub Desktop.
Lag measure
(function() {
var lastTime = +new Date();
var avgArr = [];
var avg;
setInterval(function() {
var time = +new Date();
var diff = time - lastTime;
lastTime = time;
if (avg) {
if (diff > avg * 2) {
console.log('lag: ', diff + ' ms');
}
} else {
avgArr.push(diff);
if (avgArr.length >= 100) {
avg = avgArr.reduce(function(acc, b) {
return acc + b;
}, 0) / avgArr.length;
console.log('avg: ', avg);
}
}
}, 0);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment