Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Last active August 29, 2015 14:04
Show Gist options
  • Save purplecabbage/812fa5bb8e58ee258f8d to your computer and use it in GitHub Desktop.
Save purplecabbage/812fa5bb8e58ee258f8d to your computer and use it in GitHub Desktop.
Log time to deviceready event - requires window.performance.timing
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