| OLD | NEW |
| 1 library angular.perf.mirror; | 1 library angular.perf.mirror; |
| 2 | 2 |
| 3 import '_perf.dart'; | 3 import '_perf.dart'; |
| 4 import 'dart:mirrors'; | 4 import 'dart:mirrors'; |
| 5 import 'package:angular/change_detection/dirty_checking_change_detector.dart'; | |
| 6 | 5 |
| 7 main() { | 6 main() { |
| 8 var c = new _Obj(1); | 7 var c = new Obj(1); |
| 9 InstanceMirror im = reflect(c); | 8 InstanceMirror im = reflect(c); |
| 10 Symbol symbol = const Symbol('a'); | 9 Symbol symbol = new Symbol('a'); |
| 11 _Watch head = new _Watch(); | 10 Watch head = new Watch(); |
| 12 _Watch current = head; | 11 Watch current = head; |
| 13 GetterCache getterCache = new GetterCache({}); | |
| 14 var detector = new DirtyCheckingChangeDetector<String>(getterCache); | |
| 15 for(var i=1; i < 10000; i++) { | 12 for(var i=1; i < 10000; i++) { |
| 16 _Watch next = new _Watch(); | 13 Watch next = new Watch(); |
| 17 current = (current.next = new _Watch()); | 14 current = (current.next = new Watch()); |
| 18 detector.watch(c, 'a', ''); | |
| 19 } | 15 } |
| 20 | 16 |
| 21 var dirtyCheck = () { | 17 var dirtyCheck = () { |
| 22 _Watch current = head; | 18 Watch current = head; |
| 23 while(current != null) { | 19 while(current != null) { |
| 24 if (!identical(current.lastValue, current.im.getField(current.symbol).refl
ectee)) { | 20 if (!identical(current.lastValue, current.im.getField(current.symbol).refl
ectee)) { |
| 25 throw "We should not get here"; | 21 throw "We should not get here"; |
| 26 } | 22 } |
| 27 current = current.next; | 23 current = current.next; |
| 28 } | 24 } |
| 29 }; | 25 }; |
| 30 | 26 |
| 31 var dirtyCheckFn = () { | 27 var dirtyCheckFn = () { |
| 32 _Watch current = head; | 28 Watch current = head; |
| 33 while(current != null) { | 29 while(current != null) { |
| 34 if (!identical(current.lastValue, current.getter(current.object))) { | 30 if (!identical(current.lastValue, current.getter(current.object))) { |
| 35 throw "We should not get here"; | 31 throw "We should not get here"; |
| 36 } | 32 } |
| 37 current = current.next; | 33 current = current.next; |
| 38 } | 34 } |
| 39 }; | 35 }; |
| 40 | 36 |
| 41 xtime('fieldRead', () => im.getField(symbol).reflectee ); | 37 time('fieldRead', () => im.getField(symbol).reflectee ); |
| 42 xtime('Object.observe', dirtyCheck); | 38 time('Object.observe', dirtyCheck); |
| 43 xtime('Object.observe fn()', dirtyCheckFn); | 39 time('Object.observe fn()', dirtyCheckFn); |
| 44 time('ChangeDetection', detector.collectChanges); | |
| 45 } | 40 } |
| 46 | 41 |
| 47 class _Watch { | 42 class Watch { |
| 48 dynamic lastValue = 1; | 43 dynamic lastValue = 1; |
| 49 _Watch next; | 44 Watch next; |
| 50 String location; | 45 String location; |
| 51 dynamic object = new _Obj(1); | 46 dynamic object = new Obj(1); |
| 52 InstanceMirror im; | 47 InstanceMirror im; |
| 53 Symbol symbol = const Symbol('a'); | 48 Symbol symbol = new Symbol('a'); |
| 54 Function getter = (s) => s.a; | 49 Function getter = (s) => s.a; |
| 55 | 50 |
| 56 _Watch() { | 51 Watch() { |
| 57 im = reflect(object); | 52 im = reflect(object); |
| 58 } | 53 } |
| 59 } | 54 } |
| 60 | 55 |
| 61 class _Obj { | 56 class Obj { |
| 62 var a; | 57 var a; |
| 63 | 58 |
| 64 _Obj(this.a); | 59 Obj(this.a); |
| 65 } | 60 } |
| OLD | NEW |