Last active
August 29, 2015 14:04
-
-
Save purplecabbage/812fa5bb8e58ee258f8d to your computer and use it in GitHub Desktop.
Log time to deviceready event - requires window.performance.timing
This file contains 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
document.addEventListener('deviceready',function() { | |
var deltaT = +new Date() - window.performance.timing.navigationStart; | |
var perfLog = window.localStorage.perfLog ? JSON.parse(window.localStorage.perfLog) : []; | |
perfLog.push(deltaT); | |
window.localStorage.perfLog = JSON.stringify(perfLog); | |
var maxSamples = 100; | |
if (perfLog.length < maxSamples) { | |
window.location.reload(); | |
} | |
else { | |
perfLog.sort(function (a, b) { | |
return (( a < b ) ? -1 : (( a > b ) ? 1 : 0 )); | |
}); | |
console.log("min = " + perfLog[0]); | |
console.log("max = " + perfLog[maxSamples-1]); | |
var total = 0; | |
for (var n = 0; n < maxSamples; n++) { | |
total += perfLog[n]; | |
} | |
console.log("average = " + (total / maxSamples)); | |
window.localStorage.perfLog = JSON.stringify([]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment