Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Created September 1, 2013 11:06
Show Gist options
  • Save GavinJoyce/6403776 to your computer and use it in GitHub Desktop.
Save GavinJoyce/6403776 to your computer and use it in GitHub Desktop.
Run Loop Metrics Bookmarklet
javascript:(function(){
var getTimestamp = function() { return new Date().getTime(); };
if (window.performance.now) {
getTimestamp = function() { return window.performance.now(); };
} else if (window.performance.webkitNow) {
getTimestamp = function() { return window.performance.webkitNow(); };
}
var startTime, endTime, loopCount = 0;
var onBegin = Ember.run.backburner.options.onBegin;
var wrappedOnBegin = function(current) {
loopCount++;
console.log('run loop: #' + loopCount);
startTime = getTimestamp();
onBegin();
};
Ember.run.backburner.options.onBegin = wrappedOnBegin;
var onEnd = Ember.run.backburner.options.onEnd;
var wrappedOnEnd = function(current) {
onEnd();
endTime = getTimestamp();
console.log('loop duration: ' + (endTime - startTime) + 'ms');
};
Ember.run.backburner.options.onEnd = wrappedOnEnd;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment