perf(ElementInjector): add a benchmark measuring the instantiation of element injectors without using reflection
This commit is contained in:
parent
e3b772425e
commit
c11ca944d4
|
@ -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())
|
||||
}));
|
||||
}
|
|
@ -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));
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue