After some experimentation, I found a way to get a rough idea of ββhow long it takes to render.
Scenario:
- The route to the page in the Angular application
- AJAX call to get a long list of items
- Take a list of items, go to
ng-repeat ul - View the displayed list
In an Angular application, ng-repeat is a notorious manufacturer, but it is very convenient. Performance is discussed here, and here.
Let's say that we want to get the approximate time needed to go from # 3 to # 4, since testing AJAX call performance is pretty simple.
Here is the context:
<ul> <li ng-repeat="item in items"> {{item.name}} </li> </ul>
And inside the Angular controller:
// Get items to populate ng-repeater MyApiService.getItems(query) .then( function (data) { $scope.items = data; // When callback finishes, Angular will process items // and prepare to load into DOM }, function (reason) { console.log(reason); });
The events mentioned by @runTarm, $routeChangeStart , $routeChangeSuccess and $viewContentLoaded triggered as soon as the route is loaded, but before the DOM displays the elements, so they do not solve the problem. However, through experimentation, I found that after completing the AJAX callback and typing $scope.items , Angular starts the items processing lock operation and prepares ng-repeat ul for insertion into the DOM. That way, if you get the time after the AJAX call ends and get the time again in setTimeout specified in the callback, the setTimeout callback will be queued until Angular is executed using the follower process and you get the time spent for a split second before the DOM displays, giving you the closest approximation for the rendering time. This will not be the actual rendering time, but the slow part for us is not the DOM that works, but the Angular that we are looking for to measure.
Here is an example:
// Get items to populate ng-repeater MyApiService.getItems(query) .then( function (data) { var start = new Date(); $scope.items = data; // When callback finishes, Angular will process items // and prepare to load into DOM setTimeout( function () { // Logs when Angular is done processing repeater console.log('Process time: ' + (new Date() - start)); }); // Leave timeout empty to fire on next tick }, function (reason) { console.log(reason); });