| Index: third_party/pkg/angular/perf/scope_perf.dart
|
| diff --git a/third_party/pkg/angular/perf/scope_perf.dart b/third_party/pkg/angular/perf/scope_perf.dart
|
| index 4d592cb8cc21c9041df52ad243549f082a9022d5..7701c30ed4ac461e5026d158f1e2cc0656e3803f 100644
|
| --- a/third_party/pkg/angular/perf/scope_perf.dart
|
| +++ b/third_party/pkg/angular/perf/scope_perf.dart
|
| @@ -6,62 +6,231 @@ import 'package:angular/core/parser/parser.dart';
|
| import 'package:di/di.dart';
|
| import 'package:di/dynamic_injector.dart';
|
|
|
| -main() {
|
| - var scope = new DynamicInjector(
|
| +createInjector() {
|
| + return new DynamicInjector(
|
| modules: [new Module()
|
| ..type(Parser, implementedBy: DynamicParser)
|
| ..type(ParserBackend, implementedBy: DynamicParserBackend)],
|
| - allowImplicitInjection:true).get(Scope);
|
| - var scope2, scope3, scope4, scope5;
|
| - var fill = (scope) {
|
| - for(var i = 0; i < 10000; i++) {
|
| - scope['key_$i'] = i;
|
| - }
|
| - return scope;
|
| + allowImplicitInjection:true);
|
| +}
|
| +
|
| +var reactionFn = (_, __, ___) => null;
|
| +main() {
|
| + _fieldRead();
|
| + _mapRead();
|
| + _methodInvoke0();
|
| + _methodInvoke1();
|
| + _function2();
|
| +}
|
| +
|
| +_fieldRead() {
|
| + var injector = createInjector();
|
| + var obj = new _Obj();
|
| + var scope = injector.get(Scope);
|
| + var parser = injector.get(Parser);
|
| + var parse = (exp) {
|
| + var fn = parser(exp).eval;
|
| + var o = obj;
|
| + return (s) => fn(o);
|
| };
|
| + scope.watch(parse('a'), reactionFn);
|
| + scope.watch(parse('b'), reactionFn);
|
| + scope.watch(parse('c'), reactionFn);
|
| + scope.watch(parse('d'), reactionFn);
|
| + scope.watch(parse('e'), reactionFn);
|
| + scope.watch(parse('f'), reactionFn);
|
| + scope.watch(parse('g'), reactionFn);
|
| + scope.watch(parse('h'), reactionFn);
|
| + scope.watch(parse('i'), reactionFn);
|
| + scope.watch(parse('j'), reactionFn);
|
| + scope.watch(parse('k'), reactionFn);
|
| + scope.watch(parse('l'), reactionFn);
|
| + scope.watch(parse('m'), reactionFn);
|
| + scope.watch(parse('n'), reactionFn);
|
| + scope.watch(parse('o'), reactionFn);
|
| + scope.watch(parse('p'), reactionFn);
|
| + scope.watch(parse('q'), reactionFn);
|
| + scope.watch(parse('r'), reactionFn);
|
| + scope.watch(parse('s'), reactionFn);
|
| + scope.watch(parse('t'), reactionFn);
|
| + scope.apply();
|
| + time('fieldRead', () => scope.apply());
|
| +}
|
|
|
| - scope = fill(scope);
|
| - scope2 = fill(scope.$new());
|
| - scope3 = fill(scope2.$new());
|
| - scope4 = fill(scope3.$new());
|
| - scope5 = fill(scope4.$new());
|
| +_mapRead() {
|
| + var map = {
|
| + 'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4,
|
| + 'f': 0, 'g': 1, 'h': 2, 'i': 3, 'j': 4,
|
| + 'k': 0, 'l': 1, 'm': 2, 'n': 3, 'o': 4,
|
| + 'p': 0, 'q': 1, 'r': 2, 's': 3, 't': 4};
|
| + var injector = createInjector();
|
| + var obj = new _Obj();
|
| + var scope = injector.get(Scope);
|
| + map.forEach((k, v) => scope[k] = v);
|
|
|
| - time('noop', () {});
|
| + scope.watch('a', reactionFn);
|
| + scope.watch('b', reactionFn);
|
| + scope.watch('c', reactionFn);
|
| + scope.watch('d', reactionFn);
|
| + scope.watch('e', reactionFn);
|
| + scope.watch('f', reactionFn);
|
| + scope.watch('g', reactionFn);
|
| + scope.watch('h', reactionFn);
|
| + scope.watch('i', reactionFn);
|
| + scope.watch('j', reactionFn);
|
| + scope.watch('k', reactionFn);
|
| + scope.watch('l', reactionFn);
|
| + scope.watch('m', reactionFn);
|
| + scope.watch('n', reactionFn);
|
| + scope.watch('o', reactionFn);
|
| + scope.watch('p', reactionFn);
|
| + scope.watch('q', reactionFn);
|
| + scope.watch('r', reactionFn);
|
| + scope.watch('s', reactionFn);
|
| + scope.watch('t', reactionFn);
|
| + scope.apply();
|
| + time('mapRead', () => scope.apply());
|
| +}
|
|
|
| - time('empty scope \$digest()', () {
|
| - scope.$digest();
|
| - });
|
| +_methodInvoke0() {
|
| + var context = new _Obj();
|
| + var injector = createInjector();
|
| + var obj = new _Obj();
|
| + var scope = injector.get(Scope);
|
| + scope.a = context;
|
| + scope.watch('a.methodA()', reactionFn);
|
| + scope.watch('a.methodB()', reactionFn);
|
| + scope.watch('a.methodC()', reactionFn);
|
| + scope.watch('a.methodD()', reactionFn);
|
| + scope.watch('a.methodE()', reactionFn);
|
| + scope.watch('a.methodF()', reactionFn);
|
| + scope.watch('a.methodG()', reactionFn);
|
| + scope.watch('a.methodH()', reactionFn);
|
| + scope.watch('a.methodI()', reactionFn);
|
| + scope.watch('a.methodJ()', reactionFn);
|
| + scope.watch('a.methodK()', reactionFn);
|
| + scope.watch('a.methodL()', reactionFn);
|
| + scope.watch('a.methodM()', reactionFn);
|
| + scope.watch('a.methodN()', reactionFn);
|
| + scope.watch('a.methodO()', reactionFn);
|
| + scope.watch('a.methodP()', reactionFn);
|
| + scope.watch('a.methodQ()', reactionFn);
|
| + scope.watch('a.methodR()', reactionFn);
|
| + scope.watch('a.methodS()', reactionFn);
|
| + scope.watch('a.methodT()', reactionFn);
|
| + scope.apply();
|
| + time('obj.method?()', () => scope.apply());
|
| +}
|
|
|
| - scope.a = new A();
|
| +_methodInvoke1() {
|
| + var context = new _Obj();
|
| + var injector = createInjector();
|
| + var obj = new _Obj();
|
| + var scope = injector.get(Scope);
|
| + scope.a = context;
|
| + scope.watch('a.methodA(a)', reactionFn);
|
| + scope.watch('a.methodB(a)', reactionFn);
|
| + scope.watch('a.methodC(a)', reactionFn);
|
| + scope.watch('a.methodD(a)', reactionFn);
|
| + scope.watch('a.methodE(a)', reactionFn);
|
| + scope.watch('a.methodF(a)', reactionFn);
|
| + scope.watch('a.methodG(a)', reactionFn);
|
| + scope.watch('a.methodH(a)', reactionFn);
|
| + scope.watch('a.methodI(a)', reactionFn);
|
| + scope.watch('a.methodJ(a)', reactionFn);
|
| + scope.watch('a.methodK(a)', reactionFn);
|
| + scope.watch('a.methodL(a)', reactionFn);
|
| + scope.watch('a.methodM(a)', reactionFn);
|
| + scope.watch('a.methodN(a)', reactionFn);
|
| + scope.watch('a.methodO(a)', reactionFn);
|
| + scope.watch('a.methodP(a)', reactionFn);
|
| + scope.watch('a.methodQ(a)', reactionFn);
|
| + scope.watch('a.methodR(a)', reactionFn);
|
| + scope.watch('a.methodS(a)', reactionFn);
|
| + scope.watch('a.methodT(a)', reactionFn);
|
| + scope.apply();
|
| + time('obj.method?(obj)', () => scope.apply());
|
| +}
|
|
|
| - List watchFns = new List.generate(4000, (i) => () => i);
|
| - time('adding/removing 4000 watchers', () {
|
| - List watchers = watchFns.map(scope.$watch).toList();
|
| - watchers.forEach((e) => e());
|
| - });
|
| +_function2() {
|
| + var injector = createInjector();
|
| + var obj = new _Obj();
|
| + obj.a = 1;
|
| + var scope = injector.get(Scope);
|
| + var parser = injector.get(Parser);
|
| + var aFn = parser('a').eval;
|
| + var add = () {
|
| + var fn = aFn;
|
| + var o = obj;
|
| + return (s) => fn(o) + fn(o);
|
| + };
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.watch(add(), reactionFn);
|
| + scope.apply();
|
| + time('add?(a, a)', () => scope.apply());
|
| +}
|
|
|
| - List watchers = watchFns.map(scope.$watch).toList();
|
| - time('4000 dummy watchers on scope', () => scope.$digest());
|
| - watchers.forEach((e) => e());
|
| +class _Obj {
|
| + var a = 1;
|
| + var b = 2;
|
| + var c = 3;
|
| + var d = 4;
|
| + var e = 5;
|
|
|
| - for(var i = 0; i < 1000; i++ ) {
|
| - scope.$watch('a.number', () => null);
|
| - scope.$watch('a.str', () => null);
|
| - scope.$watch('a.obj', () => null);
|
| - }
|
| + var f = 6;
|
| + var g = 7;
|
| + var h = 8;
|
| + var i = 9;
|
| + var j = 10;
|
|
|
| - time('3000 watchers on scope', () => scope.$digest());
|
| + var k = 11;
|
| + var l = 12;
|
| + var m = 13;
|
| + var n = 14;
|
| + var o = 15;
|
|
|
| - //TODO(misko): build matrics of these
|
| - time('scope[] 1 deep', () => scope['nenexistant']);
|
| - time('scope[] 2 deep', () => scope2['nenexistant']);
|
| - time('scope[] 3 deep', () => scope3['nenexistant']);
|
| - time('scope[] 4 deep', () => scope4['nenexistant']);
|
| - time('scope[] 5 deep', () => scope5['nenexistant']);
|
| -}
|
| + var p = 16;
|
| + var q = 17;
|
| + var r = 18;
|
| + var s = 19;
|
| + var t = 20;
|
|
|
| -class A {
|
| - var number = 1;
|
| - var str = 'abc';
|
| - var obj = {};
|
| + methodA([arg0]) => a;
|
| + methodB([arg0]) => b;
|
| + methodC([arg0]) => c;
|
| + methodD([arg0]) => d;
|
| + methodE([arg0]) => e;
|
| + methodF([arg0]) => f;
|
| + methodG([arg0]) => g;
|
| + methodH([arg0]) => h;
|
| + methodI([arg0]) => i;
|
| + methodJ([arg0]) => j;
|
| + methodK([arg0]) => k;
|
| + methodL([arg0]) => l;
|
| + methodM([arg0]) => m;
|
| + methodN([arg0]) => n;
|
| + methodO([arg0]) => o;
|
| + methodP([arg0]) => p;
|
| + methodQ([arg0]) => q;
|
| + methodR([arg0]) => r;
|
| + methodS([arg0]) => s;
|
| + methodT([arg0]) => t;
|
| }
|
|
|