| OLD | NEW |
| (Empty) |
| 1 library angular.perf.watch_group; | |
| 2 | |
| 3 import '_perf.dart'; | |
| 4 import 'package:angular/change_detection/dirty_checking_change_detector.dart'; | |
| 5 import 'package:angular/change_detection/watch_group.dart'; | |
| 6 import 'package:benchmark_harness/benchmark_harness.dart'; | |
| 7 | |
| 8 @MirrorsUsed( | |
| 9 targets: const [ | |
| 10 'angular.perf.watch_group' | |
| 11 ], | |
| 12 override: '*' | |
| 13 ) | |
| 14 import 'dart:mirrors' show MirrorsUsed; | |
| 15 | |
| 16 var _reactionFn = (_, __) => null; | |
| 17 var _getterCache = new GetterCache({}); | |
| 18 main() { | |
| 19 _fieldRead(); | |
| 20 _fieldReadGetter(); | |
| 21 _mapRead(); | |
| 22 _methodInvoke0(); | |
| 23 _methodInvoke1(); | |
| 24 _function2(); | |
| 25 new _CollectionCheck().report(); | |
| 26 } | |
| 27 | |
| 28 class _CollectionCheck extends BenchmarkBase { | |
| 29 List<int> list = new List.generate(1000, (i) => i); | |
| 30 var detector = new DirtyCheckingChangeDetector(_getterCache); | |
| 31 | |
| 32 _CollectionCheck(): super('change-detect List[1000]') { | |
| 33 detector | |
| 34 ..watch(list, null, 'handler') | |
| 35 ..collectChanges(); // intialize | |
| 36 } | |
| 37 | |
| 38 run() { | |
| 39 detector.collectChanges(); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 _fieldRead() { | |
| 44 var watchGrp = new RootWatchGroup( | |
| 45 new DirtyCheckingChangeDetector(_getterCache), new _Obj()) | |
| 46 ..watch(_parse('a'), _reactionFn) | |
| 47 ..watch(_parse('b'), _reactionFn) | |
| 48 ..watch(_parse('c'), _reactionFn) | |
| 49 ..watch(_parse('d'), _reactionFn) | |
| 50 ..watch(_parse('e'), _reactionFn) | |
| 51 ..watch(_parse('f'), _reactionFn) | |
| 52 ..watch(_parse('g'), _reactionFn) | |
| 53 ..watch(_parse('h'), _reactionFn) | |
| 54 ..watch(_parse('i'), _reactionFn) | |
| 55 ..watch(_parse('j'), _reactionFn) | |
| 56 ..watch(_parse('k'), _reactionFn) | |
| 57 ..watch(_parse('l'), _reactionFn) | |
| 58 ..watch(_parse('m'), _reactionFn) | |
| 59 ..watch(_parse('n'), _reactionFn) | |
| 60 ..watch(_parse('o'), _reactionFn) | |
| 61 ..watch(_parse('p'), _reactionFn) | |
| 62 ..watch(_parse('q'), _reactionFn) | |
| 63 ..watch(_parse('r'), _reactionFn) | |
| 64 ..watch(_parse('s'), _reactionFn) | |
| 65 ..watch(_parse('t'), _reactionFn); | |
| 66 | |
| 67 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 68 | |
| 69 time('fieldRead', () => watchGrp.detectChanges()); | |
| 70 } | |
| 71 | |
| 72 _fieldReadGetter() { | |
| 73 var getterCache = new GetterCache({ | |
| 74 "a": (o) => o.a, "b": (o) => o.b, "c": (o) => o.c, "d": (o) => o.d, "e": (o)
=> o.e, | |
| 75 "f": (o) => o.f, "g": (o) => o.g, "h": (o) => o.h, "i": (o) => o.i, "j": (o)
=> o.j, | |
| 76 "k": (o) => o.k, "l": (o) => o.l, "m": (o) => o.m, "n": (o) => o.n, "o": (o)
=> o.o, | |
| 77 "p": (o) => o.p, "q": (o) => o.q, "r": (o) => o.r, "s": (o) => o.s, "t": (o)
=> o.t, | |
| 78 }); | |
| 79 var watchGrp= new RootWatchGroup( | |
| 80 new DirtyCheckingChangeDetector(getterCache), new _Obj()) | |
| 81 ..watch(_parse('a'), _reactionFn) | |
| 82 ..watch(_parse('b'), _reactionFn) | |
| 83 ..watch(_parse('c'), _reactionFn) | |
| 84 ..watch(_parse('d'), _reactionFn) | |
| 85 ..watch(_parse('e'), _reactionFn) | |
| 86 ..watch(_parse('f'), _reactionFn) | |
| 87 ..watch(_parse('g'), _reactionFn) | |
| 88 ..watch(_parse('h'), _reactionFn) | |
| 89 ..watch(_parse('i'), _reactionFn) | |
| 90 ..watch(_parse('j'), _reactionFn) | |
| 91 ..watch(_parse('k'), _reactionFn) | |
| 92 ..watch(_parse('l'), _reactionFn) | |
| 93 ..watch(_parse('m'), _reactionFn) | |
| 94 ..watch(_parse('n'), _reactionFn) | |
| 95 ..watch(_parse('o'), _reactionFn) | |
| 96 ..watch(_parse('p'), _reactionFn) | |
| 97 ..watch(_parse('q'), _reactionFn) | |
| 98 ..watch(_parse('r'), _reactionFn) | |
| 99 ..watch(_parse('s'), _reactionFn) | |
| 100 ..watch(_parse('t'), _reactionFn); | |
| 101 | |
| 102 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 103 | |
| 104 time('fieldReadGetter', () => watchGrp.detectChanges()); | |
| 105 } | |
| 106 | |
| 107 _mapRead() { | |
| 108 var map = { | |
| 109 'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, | |
| 110 'f': 0, 'g': 1, 'h': 2, 'i': 3, 'j': 4, | |
| 111 'k': 0, 'l': 1, 'm': 2, 'n': 3, 'o': 4, | |
| 112 'p': 0, 'q': 1, 'r': 2, 's': 3, 't': 4}; | |
| 113 var watchGrp = new RootWatchGroup( | |
| 114 new DirtyCheckingChangeDetector(_getterCache), map) | |
| 115 ..watch(_parse('a'), _reactionFn) | |
| 116 ..watch(_parse('b'), _reactionFn) | |
| 117 ..watch(_parse('c'), _reactionFn) | |
| 118 ..watch(_parse('d'), _reactionFn) | |
| 119 ..watch(_parse('e'), _reactionFn) | |
| 120 ..watch(_parse('f'), _reactionFn) | |
| 121 ..watch(_parse('g'), _reactionFn) | |
| 122 ..watch(_parse('h'), _reactionFn) | |
| 123 ..watch(_parse('i'), _reactionFn) | |
| 124 ..watch(_parse('j'), _reactionFn) | |
| 125 ..watch(_parse('k'), _reactionFn) | |
| 126 ..watch(_parse('l'), _reactionFn) | |
| 127 ..watch(_parse('m'), _reactionFn) | |
| 128 ..watch(_parse('n'), _reactionFn) | |
| 129 ..watch(_parse('o'), _reactionFn) | |
| 130 ..watch(_parse('p'), _reactionFn) | |
| 131 ..watch(_parse('q'), _reactionFn) | |
| 132 ..watch(_parse('r'), _reactionFn) | |
| 133 ..watch(_parse('s'), _reactionFn) | |
| 134 ..watch(_parse('t'), _reactionFn); | |
| 135 | |
| 136 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 137 time('mapRead', () => watchGrp.detectChanges()); | |
| 138 } | |
| 139 | |
| 140 _methodInvoke0() { | |
| 141 var context = new _Obj(); | |
| 142 context.a = new _Obj(); | |
| 143 var watchGrp = new RootWatchGroup( | |
| 144 new DirtyCheckingChangeDetector(_getterCache), context) | |
| 145 ..watch(_method('a', 'methodA'), _reactionFn) | |
| 146 ..watch(_method('a', 'methodB'), _reactionFn) | |
| 147 ..watch(_method('a', 'methodC'), _reactionFn) | |
| 148 ..watch(_method('a', 'methodD'), _reactionFn) | |
| 149 ..watch(_method('a', 'methodE'), _reactionFn) | |
| 150 ..watch(_method('a', 'methodF'), _reactionFn) | |
| 151 ..watch(_method('a', 'methodG'), _reactionFn) | |
| 152 ..watch(_method('a', 'methodH'), _reactionFn) | |
| 153 ..watch(_method('a', 'methodI'), _reactionFn) | |
| 154 ..watch(_method('a', 'methodJ'), _reactionFn) | |
| 155 ..watch(_method('a', 'methodK'), _reactionFn) | |
| 156 ..watch(_method('a', 'methodL'), _reactionFn) | |
| 157 ..watch(_method('a', 'methodM'), _reactionFn) | |
| 158 ..watch(_method('a', 'methodN'), _reactionFn) | |
| 159 ..watch(_method('a', 'methodO'), _reactionFn) | |
| 160 ..watch(_method('a', 'methodP'), _reactionFn) | |
| 161 ..watch(_method('a', 'methodQ'), _reactionFn) | |
| 162 ..watch(_method('a', 'methodR'), _reactionFn) | |
| 163 ..watch(_method('a', 'methodS'), _reactionFn) | |
| 164 ..watch(_method('a', 'methodT'), _reactionFn); | |
| 165 | |
| 166 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 167 time('obj.method?()', () => watchGrp.detectChanges()); | |
| 168 } | |
| 169 | |
| 170 _methodInvoke1() { | |
| 171 var context = new _Obj(); | |
| 172 context.a = new _Obj(); | |
| 173 var watchGrp = new RootWatchGroup( | |
| 174 new DirtyCheckingChangeDetector(_getterCache), context) | |
| 175 ..watch(_method('a', 'methodA1', [_parse('a')]), _reactionFn) | |
| 176 ..watch(_method('a', 'methodB1', [_parse('a')]), _reactionFn) | |
| 177 ..watch(_method('a', 'methodC1', [_parse('a')]), _reactionFn) | |
| 178 ..watch(_method('a', 'methodD1', [_parse('a')]), _reactionFn) | |
| 179 ..watch(_method('a', 'methodE1', [_parse('a')]), _reactionFn) | |
| 180 ..watch(_method('a', 'methodF1', [_parse('a')]), _reactionFn) | |
| 181 ..watch(_method('a', 'methodG1', [_parse('a')]), _reactionFn) | |
| 182 ..watch(_method('a', 'methodH1', [_parse('a')]), _reactionFn) | |
| 183 ..watch(_method('a', 'methodI1', [_parse('a')]), _reactionFn) | |
| 184 ..watch(_method('a', 'methodJ1', [_parse('a')]), _reactionFn) | |
| 185 ..watch(_method('a', 'methodK1', [_parse('a')]), _reactionFn) | |
| 186 ..watch(_method('a', 'methodL1', [_parse('a')]), _reactionFn) | |
| 187 ..watch(_method('a', 'methodM1', [_parse('a')]), _reactionFn) | |
| 188 ..watch(_method('a', 'methodN1', [_parse('a')]), _reactionFn) | |
| 189 ..watch(_method('a', 'methodO1', [_parse('a')]), _reactionFn) | |
| 190 ..watch(_method('a', 'methodP1', [_parse('a')]), _reactionFn) | |
| 191 ..watch(_method('a', 'methodQ1', [_parse('a')]), _reactionFn) | |
| 192 ..watch(_method('a', 'methodR1', [_parse('a')]), _reactionFn) | |
| 193 ..watch(_method('a', 'methodS1', [_parse('a')]), _reactionFn) | |
| 194 ..watch(_method('a', 'methodT1', [_parse('a')]), _reactionFn); | |
| 195 | |
| 196 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 197 time('obj.method?(obj)', () => watchGrp.detectChanges()); | |
| 198 } | |
| 199 | |
| 200 _function2() { | |
| 201 var context = new _Obj(); | |
| 202 var watchGrp = new RootWatchGroup( | |
| 203 new DirtyCheckingChangeDetector(_getterCache), context) | |
| 204 ..watch(_add(0, _parse('a'), _parse('a')), _reactionFn) | |
| 205 ..watch(_add(1, _parse('a'), _parse('a')), _reactionFn) | |
| 206 ..watch(_add(2, _parse('a'), _parse('a')), _reactionFn) | |
| 207 ..watch(_add(3, _parse('a'), _parse('a')), _reactionFn) | |
| 208 ..watch(_add(4, _parse('a'), _parse('a')), _reactionFn) | |
| 209 ..watch(_add(5, _parse('a'), _parse('a')), _reactionFn) | |
| 210 ..watch(_add(6, _parse('a'), _parse('a')), _reactionFn) | |
| 211 ..watch(_add(7, _parse('a'), _parse('a')), _reactionFn) | |
| 212 ..watch(_add(8, _parse('a'), _parse('a')), _reactionFn) | |
| 213 ..watch(_add(9, _parse('a'), _parse('a')), _reactionFn) | |
| 214 ..watch(_add(10, _parse('a'), _parse('a')), _reactionFn) | |
| 215 ..watch(_add(11, _parse('a'), _parse('a')), _reactionFn) | |
| 216 ..watch(_add(12, _parse('a'), _parse('a')), _reactionFn) | |
| 217 ..watch(_add(13, _parse('a'), _parse('a')), _reactionFn) | |
| 218 ..watch(_add(14, _parse('a'), _parse('a')), _reactionFn) | |
| 219 ..watch(_add(15, _parse('a'), _parse('a')), _reactionFn) | |
| 220 ..watch(_add(16, _parse('a'), _parse('a')), _reactionFn) | |
| 221 ..watch(_add(17, _parse('a'), _parse('a')), _reactionFn) | |
| 222 ..watch(_add(18, _parse('a'), _parse('a')), _reactionFn) | |
| 223 ..watch(_add(19, _parse('a'), _parse('a')), _reactionFn); | |
| 224 | |
| 225 print('Watch: ${watchGrp.fieldCost}; eval: ${watchGrp.evalCost}'); | |
| 226 time('add?(a, a)', () => watchGrp.detectChanges()); | |
| 227 } | |
| 228 | |
| 229 AST _add(id, lhs, rhs) => | |
| 230 new PureFunctionAST('add$id', (a, b) => a + b, [lhs, rhs]); | |
| 231 | |
| 232 AST _method(lhs, methodName, [args]) { | |
| 233 if (args == null) args = []; | |
| 234 return new MethodAST(_parse(lhs), methodName, args); | |
| 235 } | |
| 236 | |
| 237 AST _parse(String expression) { | |
| 238 var currentAST = new ContextReferenceAST(); | |
| 239 expression.split('.').forEach((name) { | |
| 240 currentAST = new FieldReadAST(currentAST, name); | |
| 241 }); | |
| 242 return currentAST; | |
| 243 } | |
| 244 | |
| 245 | |
| 246 class _Obj { | |
| 247 var a = 1; | |
| 248 var b = 2; | |
| 249 var c = 3; | |
| 250 var d = 4; | |
| 251 var e = 5; | |
| 252 | |
| 253 var f = 6; | |
| 254 var g = 7; | |
| 255 var h = 8; | |
| 256 var i = 9; | |
| 257 var j = 10; | |
| 258 | |
| 259 var k = 11; | |
| 260 var l = 12; | |
| 261 var m = 13; | |
| 262 var n = 14; | |
| 263 var o = 15; | |
| 264 | |
| 265 var p = 16; | |
| 266 var q = 17; | |
| 267 var r = 18; | |
| 268 var s = 19; | |
| 269 var t = 20; | |
| 270 | |
| 271 methodA1(arg0) => a; | |
| 272 methodB1(arg0) => b; | |
| 273 methodC1(arg0) => c; | |
| 274 methodD1(arg0) => d; | |
| 275 methodE1(arg0) => e; | |
| 276 methodF1(arg0) => f; | |
| 277 methodG1(arg0) => g; | |
| 278 methodH1(arg0) => h; | |
| 279 methodI1(arg0) => i; | |
| 280 methodJ1(arg0) => j; | |
| 281 methodK1(arg0) => k; | |
| 282 methodL1(arg0) => l; | |
| 283 methodM1(arg0) => m; | |
| 284 methodN1(arg0) => n; | |
| 285 methodO1(arg0) => o; | |
| 286 methodP1(arg0) => p; | |
| 287 methodQ1(arg0) => q; | |
| 288 methodR1(arg0) => r; | |
| 289 methodS1(arg0) => s; | |
| 290 methodT1(arg0) => t; | |
| 291 | |
| 292 methodA() => a; | |
| 293 methodB() => b; | |
| 294 methodC() => c; | |
| 295 methodD() => d; | |
| 296 methodE() => e; | |
| 297 methodF() => f; | |
| 298 methodG() => g; | |
| 299 methodH() => h; | |
| 300 methodI() => i; | |
| 301 methodJ() => j; | |
| 302 methodK() => k; | |
| 303 methodL() => l; | |
| 304 methodM() => m; | |
| 305 methodN() => n; | |
| 306 methodO() => o; | |
| 307 methodP() => p; | |
| 308 methodQ() => q; | |
| 309 methodR() => r; | |
| 310 methodS() => s; | |
| 311 methodT() => t; | |
| 312 | |
| 313 } | |
| OLD | NEW |