feat(perf): autoscale benchmarks depending on the browser.

This commit is contained in:
Tobias Bosch 2015-01-15 15:14:54 -08:00
parent 561ad3a68c
commit 5c064c19e2
11 changed files with 70 additions and 34 deletions

View File

@ -12,7 +12,7 @@ describe('ng2 change detection benchmark', function () {
buttons: ['#ng2DetectChanges'], buttons: ['#ng2DetectChanges'],
id: 'ng2.changeDetection', id: 'ng2.changeDetection',
params: [{ params: [{
name: 'iterations', value: 500000 name: 'iterations', value: 500000, scale: 'linear'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng2 change detection benchmark', function () {
buttons: ['#baselineDetectChanges'], buttons: ['#baselineDetectChanges'],
id: 'baseline.changeDetection', id: 'baseline.changeDetection',
params: [{ params: [{
name: 'iterations', value: 500000 name: 'iterations', value: 500000, scale: 'linear'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng2 compiler benchmark', function () {
buttons: ['#compileWithBindings'], buttons: ['#compileWithBindings'],
id: 'ng2.compile.withBindings', id: 'ng2.compile.withBindings',
params: [{ params: [{
name: 'elementCount', selector: '#elementCount', value: 150 name: 'elementCount', selector: '#elementCount', value: 150, scale: 'linear'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng2 compiler benchmark', function () {
buttons: ['#compileNoBindings'], buttons: ['#compileNoBindings'],
id: 'ng2.compile.noBindings', id: 'ng2.compile.noBindings',
params: [{ params: [{
name: 'elementCount', value: 150 name: 'elementCount', value: 150, scale: 'linear'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng2 di benchmark', function () {
buttons: ['#getByToken'], buttons: ['#getByToken'],
id: 'ng2.di.getByToken', id: 'ng2.di.getByToken',
params: [{ params: [{
name: 'iterations', value: 20000 name: 'iterations', value: 20000, scale: 'linear'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng2 di benchmark', function () {
buttons: ['#getByKey'], buttons: ['#getByKey'],
id: 'ng2.di.getByKey', id: 'ng2.di.getByKey',
params: [{ params: [{
name: 'iterations', value: 20000 name: 'iterations', value: 20000, scale: 'linear'
}] }]
}); });
}); });
@ -34,7 +34,7 @@ describe('ng2 di benchmark', function () {
buttons: ['#getChild'], buttons: ['#getChild'],
id: 'ng2.di.getChild', id: 'ng2.di.getChild',
params: [{ params: [{
name: 'iterations', value: 20000 name: 'iterations', value: 20000, scale: 'linear'
}] }]
}); });
}); });
@ -45,7 +45,7 @@ describe('ng2 di benchmark', function () {
buttons: ['#instantiate'], buttons: ['#instantiate'],
id: 'ng2.di.instantiate', id: 'ng2.di.instantiate',
params: [{ params: [{
name: 'iterations', value: 10000 name: 'iterations', value: 10000, scale: 'linear'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng2 element injector benchmark', function () {
buttons: ['#instantiate'], buttons: ['#instantiate'],
id: 'ng2.elementInjector.instantiate', id: 'ng2.elementInjector.instantiate',
params: [{ params: [{
name: 'iterations', value: 20000 name: 'iterations', value: 20000, scale: 'linear'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng2 element injector benchmark', function () {
buttons: ['#instantiateDirectives'], buttons: ['#instantiateDirectives'],
id: 'ng2.elementInjector.instantiateDirectives', id: 'ng2.elementInjector.instantiateDirectives',
params: [{ params: [{
name: 'iterations', value: 20000 name: 'iterations', value: 20000, scale: 'linear'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng2 selector benchmark', function () {
buttons: ['#parse'], buttons: ['#parse'],
id: 'ng2.selector.parse', id: 'ng2.selector.parse',
params: [{ params: [{
name: 'selectors', value: 10000 name: 'selectors', value: 10000, scale: 'linear'
}] }]
}); });
}); });
@ -22,7 +22,7 @@ describe('ng2 selector benchmark', function () {
buttons: ['#addSelectable'], buttons: ['#addSelectable'],
id: 'ng2.selector.addSelectable', id: 'ng2.selector.addSelectable',
params: [{ params: [{
name: 'selectors', value: 10000 name: 'selectors', value: 10000, scale: 'linear'
}] }]
}); });
}); });
@ -33,7 +33,7 @@ describe('ng2 selector benchmark', function () {
buttons: ['#match'], buttons: ['#match'],
id: 'ng2.selector.match', id: 'ng2.selector.match',
params: [{ params: [{
name: 'selectors', value: 10000 name: 'selectors', value: 10000, scale: 'linear'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng2 tree benchmark', function () {
buttons: ['#ng2DestroyDom', '#ng2CreateDom'], buttons: ['#ng2DestroyDom', '#ng2CreateDom'],
id: 'ng2.tree', id: 'ng2.tree',
params: [{ params: [{
name: 'depth', value: 9 name: 'depth', value: 9, scale: 'log2'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng2 tree benchmark', function () {
buttons: ['#baselineDestroyDom', '#baselineCreateDom'], buttons: ['#baselineDestroyDom', '#baselineCreateDom'],
id: 'baseline.tree', id: 'baseline.tree',
params: [{ params: [{
name: 'depth', value: 9 name: 'depth', value: 9, scale: 'log2'
}] }]
}); });
}); });

View File

@ -12,7 +12,7 @@ describe('ng1.x compiler benchmark', function () {
buttons: ['#compileWithBindings'], buttons: ['#compileWithBindings'],
id: 'ng1.compile.withBindings', id: 'ng1.compile.withBindings',
params: [{ params: [{
name: 'elementCount', value: 150 name: 'elementCount', value: 150, scale: 'linear'
}] }]
}); });
}); });
@ -23,7 +23,7 @@ describe('ng1.x compiler benchmark', function () {
buttons: ['#compileNoBindings'], buttons: ['#compileNoBindings'],
id: 'ng1.compile.noBindings', id: 'ng1.compile.noBindings',
params: [{ params: [{
name: 'elementCount', value: 150 name: 'elementCount', value: 150, scale: 'linear'
}] }]
}); });
}); });

View File

@ -24,10 +24,12 @@ describe('ng1.x largetable benchmark', function () {
id: 'ng1.largetable.' + benchmarkType, id: 'ng1.largetable.' + benchmarkType,
params: [{ params: [{
name: 'columns', name: 'columns',
value: 100 value: 100,
scale: 'sqrt'
},{ },{
name: 'rows', name: 'rows',
value: 20 value: 20,
scale: 'sqrt'
},{ },{
name: 'benchmarkType', name: 'benchmarkType',
value: benchmarkType value: benchmarkType

View File

@ -12,7 +12,7 @@ describe('ng1.x tree benchmark', function () {
buttons: ['#destroyDom', '#createDom'], buttons: ['#destroyDom', '#createDom'],
id: 'ng1.tree', id: 'ng1.tree',
params: [{ params: [{
name: 'depth', value: 9 name: 'depth', value: 9, scale: 'log2'
}] }]
}); });
}); });

View File

@ -7,19 +7,53 @@ module.exports = {
}; };
function runClickBenchmark(config) { function runClickBenchmark(config) {
var url = encodeURI(config.url + '?' + config.params.map(function(param) { var globalParams = browser.params;
return param.name + '=' + param.value; getScaleFactor(globalParams.benchmark.scaling).then(function(scaleFactor) {
}).join('&')); var params = config.params.map(function(param) {
browser.get(url); return {
var buttons = config.buttons.map(function(selector) { name: param.name, value: applyScaleFactor(param.value, scaleFactor, param.scale)
return $(selector); }
}); });
var benchmarkConfig = Object.create(browser.params.benchmark); var benchmarkConfig = Object.create(globalParams.benchmark);
benchmarkConfig.id = browser.params.lang+'.'+config.id; benchmarkConfig.id = globalParams.lang+'.'+config.id;
benchmarkConfig.params = config.params; benchmarkConfig.params = params;
benchpress.runBenchmark(benchmarkConfig, function() { benchmarkConfig.scaleFactor = scaleFactor;
buttons.forEach(function(button) {
button.click(); var url = encodeURI(config.url + '?' + params.map(function(param) {
return param.name + '=' + param.value;
}).join('&'));
browser.get(url);
var buttons = config.buttons.map(function(selector) {
return $(selector);
});
benchpress.runBenchmark(benchmarkConfig, function() {
buttons.forEach(function(button) {
button.click();
});
}); });
}); });
}
function getScaleFactor(possibleScalings) {
return browser.executeScript('return navigator.userAgent').then(function(userAgent) {
var scaleFactor = 1;
possibleScalings.forEach(function(entry) {
if (userAgent.match(entry.userAgent)) {
scaleFactor = entry.value;
}
});
return scaleFactor;
});
}
function applyScaleFactor(value, scaleFactor, method) {
if (method === 'log2') {
return value + Math.log2(scaleFactor);
} else if (method === 'sqrt') {
return value * Math.sqrt(scaleFactor);
} else if (method === 'linear') {
return value * scaleFactor;
} else {
return value;
}
} }

View File

@ -27,7 +27,7 @@ config.params = {
], ],
cloudReporter: cloudReporterConfig, cloudReporter: cloudReporterConfig,
scaling: [{ scaling: [{
browserName: /chrome/, value: 0.5 userAgent: /Android/, value: 0.125
}] }]
} }
}; };