Skip to content

Commit 4bbc45e

Browse files
committed
Merge pull request #10 from SgtPooki/patch-1
ngProfileLocalDigest uses performance.now
2 parents 13c9f1b + defb8a6 commit 4bbc45e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ng-profile-local-digest.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Use: run this code snippet, then profileDirectiveDigest('#foo'); to measure
44
watchers in the #foo element (and its children along the scope tree).
55
*/
66
(function (window) {
7+
var performance = window.performance;
8+
9+
function getDiff(start, end) {
10+
return (end - start).toFixed(4);
11+
}
712

813
function profileDirectiveDigest(selector) {
914
console.assert(selector && typeof selector === 'string', 'expected selector', selector);
@@ -13,10 +18,14 @@ watchers in the #foo element (and its children along the scope tree).
1318
/* global angular */
1419
var ngEl = angular.element(el);
1520
var scope = ngEl.scope() || ngEl.isolateScope();
21+
var startTime;
22+
var endTime;
23+
1624
console.assert(scope, 'cannot find scope from element', selector);
17-
console.time(selector + ' digest');
25+
startTime = performance.now();
1826
scope.$digest();
19-
console.timeEnd(selector + ' digest');
27+
endTime = performance.now();
28+
console.log(selector, getDiff(startTime, endTime) + ' digest');
2029
}
2130

2231
window.profileDirectiveDigest = profileDirectiveDigest;

0 commit comments

Comments
 (0)