feat(benchmark): add a simple benchmark for the di module

This commit is contained in:
vsavkin
2014-10-08 16:15:38 -04:00
parent 035dc5ba44
commit 1f4caa8773
12 changed files with 298 additions and 28 deletions

View File

@ -0,0 +1,15 @@
System.import('benchmarks/di/injector_get_benchmark').then(function (bm) {
window.benchmarkSteps.push({name: 'Injector.get (token)', fn: bm.run});
}, console.log.bind(console));
System.import('benchmarks/di/injector_get_by_key_benchmark').then(function (bm) {
window.benchmarkSteps.push({name: 'Injector.get (key)', fn: bm.run});
}, console.log.bind(console));
System.import('benchmarks/di/injector_get_child_benchmark').then(function (bm) {
window.benchmarkSteps.push({name: 'Injector.get (grand x 5 child)', fn: bm.run});
}, console.log.bind(console));
System.import('benchmarks/di/injector_instantiate_benchmark').then(function (bm) {
window.benchmarkSteps.push({name: 'Injector.instantiate', fn: bm.run});
}, console.log.bind(console));

View File

@ -0,0 +1,11 @@
module.exports = function(config) {
config.set({
scripts: [
{src: '/js/traceur-runtime.js'},
{src: '/js/es6-module-loader-sans-promises.src.js'},
{src: '/js/extension-register.js'},
{src: 'register_system.js'},
{src: 'benchmark.js'}
]
});
};

View File

@ -0,0 +1,43 @@
import {Injector} from "di/di";
var count = 0;
export function run () {
var bindings = [A, B, C, D, E];
var injector = new Injector(bindings);
for (var i = 0; i < 20000; ++i) {
injector.get(D);
injector.get(E);
}
}
class A {
constructor() {
count++;
}
}
class B {
constructor(a:A) {
count++;
}
}
class C {
constructor(b:B) {
count++;
}
}
class D {
constructor(c:C, b:B) {
count++;
}
}
class E {
constructor(d:D, c:C) {
count++;
}
}

View File

@ -0,0 +1,46 @@
import {Injector, Key} from "di/di";
var count = 0;
export function run () {
var bindings = [A, B, C, D, E];
var injector = new Injector(bindings);
var D_KEY = Key.get(D);
var E_KEY = Key.get(E);
for (var i = 0; i < 20000; ++i) {
injector.get(D_KEY);
injector.get(E_KEY);
}
}
class A {
constructor() {
count++;
}
}
class B {
constructor(a:A) {
count++;
}
}
class C {
constructor(b:B) {
count++;
}
}
class D {
constructor(c:C, b:B) {
count++;
}
}
class E {
constructor(d:D, c:C) {
count++;
}
}

View File

@ -0,0 +1,49 @@
import {Injector, Key} from "di/di";
var count = 0;
export function run () {
var bindings = [A, B, C, D, E];
var injector = new Injector(bindings);
var childInjector = injector.
createChild([]).
createChild([]).
createChild([]).
createChild([]).
createChild([]);
for (var i = 0; i < 20000; ++i) {
childInjector.get(D);
childInjector.get(E);
}
}
class A {
constructor() {
count++;
}
}
class B {
constructor(a:A) {
count++;
}
}
class C {
constructor(b:B) {
count++;
}
}
class D {
constructor(c:C, b:B) {
count++;
}
}
class E {
constructor(d:D, c:C) {
count++;
}
}

View File

@ -0,0 +1,45 @@
import {Injector, Key} from "di/di";
var count = 0;
export function run () {
var bindings = [A, B, C, D];
var injector = new Injector(bindings);
for (var i = 0; i < 1000; ++i) {
var child = injector.createChild([E]);
child.get(E);
}
console.log(count)
}
class A {
constructor() {
count++;
}
}
class B {
constructor(a:A) {
count++;
}
}
class C {
constructor(b:B) {
count++;
}
}
class D {
constructor(c:C, b:B) {
count++;
}
}
class E {
constructor(d:D, c:C) {
count++;
}
}

View File

View File

@ -0,0 +1,10 @@
System.paths = {
'core/*': '/js/core/lib/*.js',
'change_detection/*': '/js/change_detection/lib/*.js',
'facade/*': '/js/facade/lib/*.js',
'di/*': '/js/di/lib/*.js',
'rtts_assert/*': '/js/rtts_assert/lib/*.js',
'test_lib/*': '/js/test_lib/lib/*.js',
'benchmarks/*': '/js/benchmarks/lib/*.js'
};
register(System);