diff --git a/modules/benchmarks/src/element_injector/benchmark.dart b/modules/benchmarks/src/element_injector/benchmark.dart index edadf50d3d..2b7adff902 100644 --- a/modules/benchmarks/src/element_injector/benchmark.dart +++ b/modules/benchmarks/src/element_injector/benchmark.dart @@ -1,6 +1,8 @@ library element_injector_benchmark; import './instantiate_benchmark.dart' as ib; +import './instantiate_benchmark_codegen.dart' as ibc; +import './instantiate_directive_benchmark.dart' as idb; import 'dart:js' as js; main () { @@ -8,4 +10,14 @@ main () { "name": "ElementInjector.instantiate + instantiateDirectives", "fn": new js.JsFunction.withThis((_) => ib.run()) })); + + js.context['benchmarkSteps'].add(new js.JsObject.jsify({ + "name": "ElementInjector.instantiateDirectives", + "fn": new js.JsFunction.withThis((_) => idb.run()) + })); + + js.context['benchmarkSteps'].add(new js.JsObject.jsify({ + "name": "ElementInjector.instantiate + instantiateDirectives (codegen)", + "fn": new js.JsFunction.withThis((_) => ibc.run()) + })); } \ No newline at end of file diff --git a/modules/benchmarks/src/element_injector/benchmark.es5 b/modules/benchmarks/src/element_injector/benchmark.es5 index 874e1e0c73..222a86db68 100644 --- a/modules/benchmarks/src/element_injector/benchmark.es5 +++ b/modules/benchmarks/src/element_injector/benchmark.es5 @@ -4,4 +4,8 @@ System.import('benchmarks/element_injector/instantiate_benchmark').then(function System.import('benchmarks/element_injector/instantiate_directive_benchmark').then(function (bm) { window.benchmarkSteps.push({name: 'ElementInjector.instantiateDirectives', fn: bm.run}); +}, console.log.bind(console)); + +System.import('benchmarks/element_injector/instantiate_benchmark_codegen').then(function (bm) { + window.benchmarkSteps.push({name: 'ElementInjector.instantiate + instantiateDirectives (codegen)', fn: bm.run}); }, console.log.bind(console)); \ No newline at end of file diff --git a/modules/benchmarks/src/element_injector/instantiate_benchmark.js b/modules/benchmarks/src/element_injector/instantiate_benchmark.js index 46c688977d..2e3dc9367b 100644 --- a/modules/benchmarks/src/element_injector/instantiate_benchmark.js +++ b/modules/benchmarks/src/element_injector/instantiate_benchmark.js @@ -1,6 +1,7 @@ import {Injector} from 'di/di'; import {ProtoElementInjector} from 'core/compiler/element_injector'; +var ITERATIONS = 20000; var count = 0; export function run () { @@ -8,7 +9,7 @@ export function run () { var bindings = [A, B, C]; var proto = new ProtoElementInjector(null, bindings, []); - for (var i = 0; i < 20000; ++i) { + for (var i = 0; i < ITERATIONS; ++i) { var ei = proto.instantiate({view:null}); ei.instantiateDirectives(appInjector); } diff --git a/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js b/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js new file mode 100644 index 0000000000..00fe76c4b1 --- /dev/null +++ b/modules/benchmarks/src/element_injector/instantiate_benchmark_codegen.js @@ -0,0 +1,42 @@ +import {Binding, Dependency, Key, Injector} from 'di/di'; +import {ProtoElementInjector} from 'core/compiler/element_injector'; + +var ITERATIONS = 20000; +var count = 0; + +export function run () { + var appInjector = new Injector([]); + + var bindings = [ + new Binding(Key.get(A), () => new A(), [], false), + new Binding(Key.get(B), () => new B(), [], false), + new Binding(Key.get(C), (a,b) => new C(a,b), [ + new Dependency(Key.get(A), false, false, []), + new Dependency(Key.get(B), false, false, []) + ], false)]; + + + var proto = new ProtoElementInjector(null, bindings, []); + for (var i = 0; i < ITERATIONS; ++i) { + var ei = proto.instantiate({view:null}); + ei.instantiateDirectives(appInjector); + } +} + +class A { + constructor() { + count++; + } +} + +class B { + constructor() { + count++; + } +} + +class C { + constructor(a:A, b:B) { + count++; + } +} \ No newline at end of file diff --git a/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js b/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js index 6cd8ff00df..29591f4215 100644 --- a/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js +++ b/modules/benchmarks/src/element_injector/instantiate_directive_benchmark.js @@ -1,6 +1,7 @@ import {Injector} from 'di/di'; import {ProtoElementInjector} from 'core/compiler/element_injector'; +var ITERATIONS = 20000; var count = 0; export function run () { @@ -10,7 +11,7 @@ export function run () { var proto = new ProtoElementInjector(null, bindings, []); var ei = proto.instantiate({view:null}); - for (var i = 0; i < 20000; ++i) { + for (var i = 0; i < ITERATIONS; ++i) { ei.clearDirectives(); ei.instantiateDirectives(appInjector); }