Skip to content

Instantly share code, notes, and snippets.

@sorenlouv
Last active August 29, 2015 14:01
Show Gist options
  • Save sorenlouv/abc62b1430d06f5c54ee to your computer and use it in GitHub Desktop.
Save sorenlouv/abc62b1430d06f5c54ee to your computer and use it in GitHub Desktop.
Performance bookmarklet for Angularjs
var bindings = document.getElementsByClassName('ng-binding').length;
var scopes = document.getElementsByClassName('ng-scope').length;
var bodyScope = angular.element(document.querySelector('body')).scope();
var watchers = bodyScope && bodyScope.$$watchers ? bodyScope.$$watchers.length : '?';
var getWatchers = function () {
var root = document.getElementsByTagName('body')[0];
var numberOfWatches = 0;
var f = function (element) {
var $element = angular.element(element);
var watchers = $element.scope().$$watchers;
if(watchers){
numberOfWatches += watchers.length;
}
angular.forEach($element.children(), function (childElement) {
f(childElement);
});
};
f(root);
return numberOfWatches;
};
console.log('Bindings: ', bindings);
console.log('Scopes: ', scopes);
console.log('Watchers (Body): ', watchers);
//console.log('Watchers (Entire page): ', getWatchers());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment