-
Notifications
You must be signed in to change notification settings - Fork 199
/
ng-find-expensive-digest.js
33 lines (30 loc) · 1 KB
/
ng-find-expensive-digest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// assumes profileDirectiveDigest(selector)
// use: findExpensiveDigest(selector1, selector2, ...);
/* global profileDirectiveDigest */
(function (window) {
function findExpensiveDigest() {
if (typeof profileDirectiveDigest !== 'function') {
throw new Error('cannot find profileDirectiveDigest function');
}
var selectors = Array.prototype.slice.call(arguments, 0);
var durations = selectors.map(function timeSelectorDigest(selector) {
/* global performance */
var started = performance.now();
profileDirectiveDigest(selector);
var takes = performance.now() - started;
return takes;
});
var merged = selectors.map(function (selector, k) {
return {
selector: selector,
takes: durations[k]
};
});
merged = merged.sort(function (a, b) {
return b.takes - a.takes;
});
console.log('elements with expensive digest cycles');
console.table(merged);
}
window.findExpensiveDigest = findExpensiveDigest;
}(window));