Skip to content

Instantly share code, notes, and snippets.

@tkadlec
Created April 23, 2015 11:54
Show Gist options
  • Save tkadlec/7e352b74b1961a3e36d7 to your computer and use it in GitHub Desktop.
Save tkadlec/7e352b74b1961a3e36d7 to your computer and use it in GitHub Desktop.
Super simple example of adding perf timing to the page display during dev work
(function () {
var perfBar = function(budget) {
window.onload = function() {
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var timing = window.performance.timing,
now = new Date().getTime(),
output, loadTime;
if (!timing) {
//fail silently
return;
}
budget = budget ? budget : 1000;
var start = timing.navigationStart;
var results = document.createElement('div');
results.setAttribute('id', 'results');
loadTime = now - start;
results.innerHTML = (now - start) + "ms";
if (loadTime > budget) {
results.className += ' overBudget';
} else {
results.className += ' underBudget';
}
document.body.appendChild(results);
}
};
window.perfBar = perfBar;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment