What is a simple way to measure the duration of the angularjs digest cycle? There exist various methods to analyze the performance of the digest cycle, however each comes wi
for strict mode, one running of digest cucle, run it in f12 console in chrome
angular.element(document).injector().invoke(['$rootScope',function($rootScope) { var a = performance.now(); $rootScope.$apply(); return performance.now()-a; }])
The following answer will tell you the idle performance of the $digest loop, ie., the performance of digest when none of your watch expressions change. This is helpful if your application seems sluggish even when the view isn't changing. For more complex situations, see aet's answer.
Type the following into the console:
angular.element(document).injector().invoke(function($rootScope) {
var a = performance.now();
$rootScope.$apply();
console.log(performance.now()-a);
})
The result will give you the duration of the digest cycle, in milliseconds. The smaller the number, the better.
NOTE:
Domi noted in the comments:
angular.element(document)
will not yield much if you used theng-app
directive for initialization. In that case, get theng-app
element instead. E.g. by doingangular.element('#ng-app')
You can also try:
angular.element(document.querySelector('[ng-app]')).injector().invoke(function($rootScope) {
var a = performance.now();
$rootScope.$apply();
console.log(performance.now()-a);
})