| OLD | NEW |
| 1 library angular.perf.invoke; | 1 library angular.perf.invoke; |
| 2 | 2 |
| 3 import 'package:benchmark_harness/benchmark_harness.dart'; | 3 import '_perf.dart'; |
| 4 import 'dart:async'; |
| 4 | 5 |
| 5 main() { | 6 main() { |
| 6 new MonomorphicClosure0ListInvoke().report(); | 7 var handleDirect = (a, b, c) => a; |
| 7 new PolymorphicMethod0ListInvoke().report(); | 8 var wrap = new Wrap(); |
| 8 new PolymorphicClosure0ListInvoke().report(); | 9 var handleDirectNamed = ({a, b, c}) => a; |
| 9 new PolymorphicMethod1ListInvoke().report(); | 10 var handleIndirect = (e) => e.a; |
| 10 new PolymorphicClosure1ListInvoke().report(); | 11 var streamC = new StreamController(sync:true); |
| 12 var stream = streamC.stream..listen(handleIndirect); |
| 13 |
| 14 time('direct', () => handleDirect(1, 2, 3) ); |
| 15 time('.call', () => wrap(1, 2, 3) ); |
| 16 time('directNamed', () => handleDirectNamed(a:1, b:2, c:3) ); |
| 17 time('indirect', () => handleIndirect(new Container(1, 2, 3)) ); |
| 18 time('stream', () => streamC.add(new Container(1, 2, 3))); |
| 11 } | 19 } |
| 12 | 20 |
| 13 var closure0Factory = [ | 21 class Container { |
| 14 () => () => 0, | 22 var a; |
| 15 () => () => 1, | 23 var b; |
| 16 () => () => 2, | 24 var c; |
| 17 () => () => 3, | |
| 18 () => () => 4, | |
| 19 () => () => 5, | |
| 20 () => () => 6, | |
| 21 () => () => 7, | |
| 22 () => () => 8, | |
| 23 () => () => 9, | |
| 24 ]; | |
| 25 | 25 |
| 26 var closure1Factory = [ | 26 Container(this.a, this.b, this.c); |
| 27 () => (i) => 0, | |
| 28 () => (i) => 1, | |
| 29 () => (i) => 2, | |
| 30 () => (i) => 3, | |
| 31 () => (i) => 4, | |
| 32 () => (i) => 5, | |
| 33 () => (i) => 6, | |
| 34 () => (i) => 7, | |
| 35 () => (i) => 8, | |
| 36 () => (i) => 9, | |
| 37 ]; | |
| 38 | |
| 39 var instanceFactory = [ | |
| 40 () => new Obj0(), | |
| 41 () => new Obj1(), | |
| 42 () => new Obj2(), | |
| 43 () => new Obj3(), | |
| 44 () => new Obj4(), | |
| 45 () => new Obj5(), | |
| 46 () => new Obj6(), | |
| 47 () => new Obj7(), | |
| 48 () => new Obj8(), | |
| 49 () => new Obj9(), | |
| 50 ]; | |
| 51 | |
| 52 class Obj0 { method0() => 0; method1(i) => 0; } | |
| 53 class Obj1 { method0() => 1; method1(i) => 1; } | |
| 54 class Obj2 { method0() => 2; method1(i) => 2; } | |
| 55 class Obj3 { method0() => 3; method1(i) => 3; } | |
| 56 class Obj4 { method0() => 4; method1(i) => 4; } | |
| 57 class Obj5 { method0() => 5; method1(i) => 5; } | |
| 58 class Obj6 { method0() => 6; method1(i) => 6; } | |
| 59 class Obj7 { method0() => 7; method1(i) => 7; } | |
| 60 class Obj8 { method0() => 8; method1(i) => 8; } | |
| 61 class Obj9 { method0() => 9; method1(i) => 9; } | |
| 62 | |
| 63 class PolymorphicClosure0ListInvoke extends BenchmarkBase { | |
| 64 PolymorphicClosure0ListInvoke() : super('PolymorphicClosure0ListInvoke'); | |
| 65 | |
| 66 var list = new List.generate(10000, (i) => closure0Factory[i%10]()); | |
| 67 | |
| 68 run() { | |
| 69 int sum = 0; | |
| 70 for(var i=0; i < list.length; i++) { | |
| 71 sum += list[i](); | |
| 72 } | |
| 73 return sum; | |
| 74 } | |
| 75 } | 27 } |
| 76 | 28 |
| 77 class MonomorphicClosure0ListInvoke extends BenchmarkBase { | 29 class Wrap { |
| 78 MonomorphicClosure0ListInvoke() : super('MonomorphicClosure0ListInvoke'); | 30 call(a, b, c) => a + b + c; |
| 79 | |
| 80 var list = new List.generate(10000, (i) => closure0Factory[0]()); | |
| 81 | |
| 82 run() { | |
| 83 int sum = 0; | |
| 84 for(var i=0; i < list.length; i++) { | |
| 85 sum += list[i](); | |
| 86 } | |
| 87 return sum; | |
| 88 } | |
| 89 } | 31 } |
| 90 | |
| 91 class PolymorphicClosure1ListInvoke extends BenchmarkBase { | |
| 92 PolymorphicClosure1ListInvoke() : super('PolymorphicClosure1ListInvoke'); | |
| 93 | |
| 94 var list = new List.generate(10000, (i) => closure1Factory[i%10]()); | |
| 95 | |
| 96 run() { | |
| 97 int sum = 0; | |
| 98 for(var i=0; i < list.length; i++) { | |
| 99 sum += list[i](i); | |
| 100 } | |
| 101 return sum; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 class PolymorphicMethod0ListInvoke extends BenchmarkBase { | |
| 106 PolymorphicMethod0ListInvoke() : super('PolymorphicMethod0ListInvoke'); | |
| 107 | |
| 108 var list = new List.generate(10000, (i) => instanceFactory[i%10]()); | |
| 109 | |
| 110 run() { | |
| 111 int sum = 0; | |
| 112 for(var i=0; i < list.length; i++) { | |
| 113 sum += list[i].method0(); | |
| 114 } | |
| 115 return sum; | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 class PolymorphicMethod1ListInvoke extends BenchmarkBase { | |
| 120 PolymorphicMethod1ListInvoke() : super('PolymorphicMethod1ListInvoke'); | |
| 121 | |
| 122 var list = new List.generate(10000, (i) => instanceFactory[i%10]()); | |
| 123 | |
| 124 run() { | |
| 125 int sum = 0; | |
| 126 for(var i=0; i < list.length; i++) { | |
| 127 sum += list[i].method1(i); | |
| 128 } | |
| 129 return sum; | |
| 130 } | |
| 131 } | |
| 132 | |
| OLD | NEW |