Skip to content

Instantly share code, notes, and snippets.

@ovidiuch
Created June 24, 2013 14:24
Show Gist options
  • Save ovidiuch/5850424 to your computer and use it in GitHub Desktop.
Save ovidiuch/5850424 to your computer and use it in GitHub Desktop.
Benchmarking the loading time of app.ubervu.com, behind the scenes of the Loading Animation
function getTime() {
return new Date().getTime() / 1000;
}
function seconds(time) {
return time.toFixed(2) + 's';
}
// Start counting as soon as the website loads
var startedLoadingAt = getTime();
var loadingTime = 0;
var timerInterval = setInterval(function() {
loadingTime = getTime() - startedLoadingAt;
// Clear console before showing new time to only show current time
console.clear();
console.log('Loading ubervu for ' + seconds(loadingTime));
// Since there's no easy hook for when the loading animation is rendered just
// set its overlay with every iteration
if (jQuery)
$('#loading-animation').css('opacity', 0.5);
// Same thing for catching when the loading animation is removed, check
// every time
if (!$('#loading-animation').is(':visible')) {
console.clear();
console.log('Finished loading ubervu in ' + seconds(loadingTime));
// Stop interval, that's it
clearInterval(timerInterval);
}
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment