feat(change_detection): add benchmarks
This commit is contained in:
parent
6e8175a816
commit
9a9a13a553
|
@ -8,3 +8,5 @@ dependencies:
|
|||
path: ../di
|
||||
core:
|
||||
path: ../core
|
||||
change_detection:
|
||||
path: ../change_detection
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
library benchmark;
|
||||
|
||||
import './change_detection_benchmark.dart' as cdb;
|
||||
import 'dart:js' as js;
|
||||
|
||||
main () {
|
||||
js.context['benchmarkSteps'].add(new js.JsObject.jsify({
|
||||
"name": "Change Detection",
|
||||
"fn": new js.JsFunction.withThis((_) => cdb.run())
|
||||
}));
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
System.import('benchmarks/change_detection/change_detection_benchmark').then(function (bm) {
|
||||
window.benchmarkSteps.push({name: 'ChangeDetection', fn: bm.run});
|
||||
}, console.log.bind(console));
|
|
@ -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'}
|
||||
]
|
||||
});
|
||||
};
|
|
@ -0,0 +1,60 @@
|
|||
import {ListWrapper, MapWrapper} from 'facade/collection';
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
import {Lexer} from 'change_detection/parser/lexer';
|
||||
import {reflector} from 'reflection/reflection';
|
||||
|
||||
import {
|
||||
ChangeDetector,
|
||||
ProtoRecordRange,
|
||||
WatchGroupDispatcher,
|
||||
} from 'change_detection/change_detector';
|
||||
|
||||
|
||||
var ITERATIONS = 100000;
|
||||
|
||||
export function run () {
|
||||
reflector.registerGetters({
|
||||
'a': function(obj){return obj.a},
|
||||
'b': function(obj){return obj.b},
|
||||
'c': function(obj){return obj.c}
|
||||
});
|
||||
|
||||
reflector.registerSetters({
|
||||
'a': function(obj, v){return obj.a = v},
|
||||
'b': function(obj, v){return obj.b = v},
|
||||
'c': function(obj, v){return obj.c = v}
|
||||
});
|
||||
|
||||
var parser = new Parser(new Lexer());
|
||||
var astWithSource = parser.parseBinding('a + b * c');
|
||||
|
||||
var prr = new ProtoRecordRange();
|
||||
prr.addRecordsFromAST(astWithSource.ast, 'memo', false);
|
||||
|
||||
var dispatcher = new DummyDispatcher();
|
||||
var rr = prr.instantiate(dispatcher, MapWrapper.create());
|
||||
rr.setContext(new Component());
|
||||
|
||||
var cd = new ChangeDetector(rr);
|
||||
for (var i = 0; i < ITERATIONS; ++i) {
|
||||
cd.detectChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DummyDispatcher extends WatchGroupDispatcher {
|
||||
onRecordChange(record, context) {
|
||||
}
|
||||
}
|
||||
|
||||
class Component {
|
||||
a:number;
|
||||
b:number;
|
||||
c:number;
|
||||
|
||||
constructor() {
|
||||
this.a = 1;
|
||||
this.b = 2;
|
||||
this.c = 3;
|
||||
}
|
||||
}
|
|
@ -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);
|
Loading…
Reference in New Issue