Skip to content

Instantly share code, notes, and snippets.

@toddhgardner
Last active December 28, 2015 09:19
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 toddhgardner/7478573 to your computer and use it in GitHub Desktop.
Save toddhgardner/7478573 to your computer and use it in GitHub Desktop.
Gathering actual performance from the browser in real time
(function (window) {
var iterations = 100;
var sampling = 1000;
var counters = [];
var i = 0, j, sum = 0, mean;
var lastNow = window.performance.now();
var interval = setInterval(function () {
var now = window.performance.now();
counters.push(now - lastNow - sampling);
lastNow = now;
i++;
if (i >= iterations) {
clearInterval(interval);
for(j=0;j<counters.length;j++) {
sum += counters[j];
}
mean = sum/counters.length;
console.log('performance result. Sum: ' + sum + ' Mean: ' + mean);
}
}, sampling);
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment