Last active
December 28, 2015 09:19
-
-
Save toddhgardner/7478573 to your computer and use it in GitHub Desktop.
Gathering actual performance from the browser in real time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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