perf(ElementInjector): add a benchmark measuring the instantiation of element injectors without using reflection

This commit is contained in:
vsavkin 2014-10-27 16:09:10 -04:00
parent e3b772425e
commit c11ca944d4
5 changed files with 62 additions and 2 deletions

View File

@ -1,6 +1,8 @@
library element_injector_benchmark; library element_injector_benchmark;
import './instantiate_benchmark.dart' as ib; 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; import 'dart:js' as js;
main () { main () {
@ -8,4 +10,14 @@ main () {
"name": "ElementInjector.instantiate + instantiateDirectives", "name": "ElementInjector.instantiate + instantiateDirectives",
"fn": new js.JsFunction.withThis((_) => ib.run()) "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())
}));
} }

View File

@ -4,4 +4,8 @@ System.import('benchmarks/element_injector/instantiate_benchmark').then(function
System.import('benchmarks/element_injector/instantiate_directive_benchmark').then(function (bm) { System.import('benchmarks/element_injector/instantiate_directive_benchmark').then(function (bm) {
window.benchmarkSteps.push({name: 'ElementInjector.instantiateDirectives', fn: bm.run}); 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)); }, console.log.bind(console));

View File

@ -1,6 +1,7 @@
import {Injector} from 'di/di'; import {Injector} from 'di/di';
import {ProtoElementInjector} from 'core/compiler/element_injector'; import {ProtoElementInjector} from 'core/compiler/element_injector';
var ITERATIONS = 20000;
var count = 0; var count = 0;
export function run () { export function run () {
@ -8,7 +9,7 @@ export function run () {
var bindings = [A, B, C]; var bindings = [A, B, C];
var proto = new ProtoElementInjector(null, bindings, []); 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}); var ei = proto.instantiate({view:null});
ei.instantiateDirectives(appInjector); ei.instantiateDirectives(appInjector);
} }

View File

@ -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++;
}
}

View File

@ -1,6 +1,7 @@
import {Injector} from 'di/di'; import {Injector} from 'di/di';
import {ProtoElementInjector} from 'core/compiler/element_injector'; import {ProtoElementInjector} from 'core/compiler/element_injector';
var ITERATIONS = 20000;
var count = 0; var count = 0;
export function run () { export function run () {
@ -10,7 +11,7 @@ export function run () {
var proto = new ProtoElementInjector(null, bindings, []); var proto = new ProtoElementInjector(null, bindings, []);
var ei = proto.instantiate({view:null}); var ei = proto.instantiate({view:null});
for (var i = 0; i < 20000; ++i) { for (var i = 0; i < ITERATIONS; ++i) {
ei.clearDirectives(); ei.clearDirectives();
ei.instantiateDirectives(appInjector); ei.instantiateDirectives(appInjector);
} }