From 5c064c19e27e98019367b35bb4a1cbbfabc2ec15 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 15 Jan 2015 15:14:54 -0800 Subject: [PATCH] feat(perf): autoscale benchmarks depending on the browser. --- .../e2e_test/change_detection_perf.es6 | 4 +- modules/benchmarks/e2e_test/compiler_perf.es6 | 4 +- modules/benchmarks/e2e_test/di_perf.es6 | 8 +-- .../e2e_test/element_injector_perf.es6 | 4 +- modules/benchmarks/e2e_test/selector_perf.es6 | 6 +- modules/benchmarks/e2e_test/tree_perf.es6 | 4 +- .../e2e_test/compiler_perf.es6 | 4 +- .../e2e_test/largetable_perf.es6 | 6 +- .../e2e_test/tree_perf.es6 | 2 +- modules/e2e_test_lib/e2e_test/perf_util.es6 | 60 +++++++++++++++---- protractor-perf-shared.js | 2 +- 11 files changed, 70 insertions(+), 34 deletions(-) diff --git a/modules/benchmarks/e2e_test/change_detection_perf.es6 b/modules/benchmarks/e2e_test/change_detection_perf.es6 index f26aa0a02c..207432e7f4 100644 --- a/modules/benchmarks/e2e_test/change_detection_perf.es6 +++ b/modules/benchmarks/e2e_test/change_detection_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 change detection benchmark', function () { buttons: ['#ng2DetectChanges'], id: 'ng2.changeDetection', params: [{ - name: 'iterations', value: 500000 + name: 'iterations', value: 500000, scale: 'linear' }] }); }); @@ -23,7 +23,7 @@ describe('ng2 change detection benchmark', function () { buttons: ['#baselineDetectChanges'], id: 'baseline.changeDetection', params: [{ - name: 'iterations', value: 500000 + name: 'iterations', value: 500000, scale: 'linear' }] }); }); diff --git a/modules/benchmarks/e2e_test/compiler_perf.es6 b/modules/benchmarks/e2e_test/compiler_perf.es6 index 894f862c54..cc2997b676 100644 --- a/modules/benchmarks/e2e_test/compiler_perf.es6 +++ b/modules/benchmarks/e2e_test/compiler_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 compiler benchmark', function () { buttons: ['#compileWithBindings'], id: 'ng2.compile.withBindings', 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'], id: 'ng2.compile.noBindings', params: [{ - name: 'elementCount', value: 150 + name: 'elementCount', value: 150, scale: 'linear' }] }); }); diff --git a/modules/benchmarks/e2e_test/di_perf.es6 b/modules/benchmarks/e2e_test/di_perf.es6 index 0f4b04bd9e..2f15caaeef 100644 --- a/modules/benchmarks/e2e_test/di_perf.es6 +++ b/modules/benchmarks/e2e_test/di_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 di benchmark', function () { buttons: ['#getByToken'], id: 'ng2.di.getByToken', params: [{ - name: 'iterations', value: 20000 + name: 'iterations', value: 20000, scale: 'linear' }] }); }); @@ -23,7 +23,7 @@ describe('ng2 di benchmark', function () { buttons: ['#getByKey'], id: 'ng2.di.getByKey', params: [{ - name: 'iterations', value: 20000 + name: 'iterations', value: 20000, scale: 'linear' }] }); }); @@ -34,7 +34,7 @@ describe('ng2 di benchmark', function () { buttons: ['#getChild'], id: 'ng2.di.getChild', params: [{ - name: 'iterations', value: 20000 + name: 'iterations', value: 20000, scale: 'linear' }] }); }); @@ -45,7 +45,7 @@ describe('ng2 di benchmark', function () { buttons: ['#instantiate'], id: 'ng2.di.instantiate', params: [{ - name: 'iterations', value: 10000 + name: 'iterations', value: 10000, scale: 'linear' }] }); }); diff --git a/modules/benchmarks/e2e_test/element_injector_perf.es6 b/modules/benchmarks/e2e_test/element_injector_perf.es6 index b36f1de409..df3b0e06ff 100644 --- a/modules/benchmarks/e2e_test/element_injector_perf.es6 +++ b/modules/benchmarks/e2e_test/element_injector_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 element injector benchmark', function () { buttons: ['#instantiate'], id: 'ng2.elementInjector.instantiate', params: [{ - name: 'iterations', value: 20000 + name: 'iterations', value: 20000, scale: 'linear' }] }); }); @@ -23,7 +23,7 @@ describe('ng2 element injector benchmark', function () { buttons: ['#instantiateDirectives'], id: 'ng2.elementInjector.instantiateDirectives', params: [{ - name: 'iterations', value: 20000 + name: 'iterations', value: 20000, scale: 'linear' }] }); }); diff --git a/modules/benchmarks/e2e_test/selector_perf.es6 b/modules/benchmarks/e2e_test/selector_perf.es6 index 37850200c7..6573320afa 100644 --- a/modules/benchmarks/e2e_test/selector_perf.es6 +++ b/modules/benchmarks/e2e_test/selector_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 selector benchmark', function () { buttons: ['#parse'], id: 'ng2.selector.parse', params: [{ - name: 'selectors', value: 10000 + name: 'selectors', value: 10000, scale: 'linear' }] }); }); @@ -22,7 +22,7 @@ describe('ng2 selector benchmark', function () { buttons: ['#addSelectable'], id: 'ng2.selector.addSelectable', params: [{ - name: 'selectors', value: 10000 + name: 'selectors', value: 10000, scale: 'linear' }] }); }); @@ -33,7 +33,7 @@ describe('ng2 selector benchmark', function () { buttons: ['#match'], id: 'ng2.selector.match', params: [{ - name: 'selectors', value: 10000 + name: 'selectors', value: 10000, scale: 'linear' }] }); }); diff --git a/modules/benchmarks/e2e_test/tree_perf.es6 b/modules/benchmarks/e2e_test/tree_perf.es6 index 0ca4ca260a..dde04ff6c7 100644 --- a/modules/benchmarks/e2e_test/tree_perf.es6 +++ b/modules/benchmarks/e2e_test/tree_perf.es6 @@ -12,7 +12,7 @@ describe('ng2 tree benchmark', function () { buttons: ['#ng2DestroyDom', '#ng2CreateDom'], id: 'ng2.tree', params: [{ - name: 'depth', value: 9 + name: 'depth', value: 9, scale: 'log2' }] }); }); @@ -23,7 +23,7 @@ describe('ng2 tree benchmark', function () { buttons: ['#baselineDestroyDom', '#baselineCreateDom'], id: 'baseline.tree', params: [{ - name: 'depth', value: 9 + name: 'depth', value: 9, scale: 'log2' }] }); }); diff --git a/modules/benchmarks_external/e2e_test/compiler_perf.es6 b/modules/benchmarks_external/e2e_test/compiler_perf.es6 index d6cbe89613..bf019ff3c8 100644 --- a/modules/benchmarks_external/e2e_test/compiler_perf.es6 +++ b/modules/benchmarks_external/e2e_test/compiler_perf.es6 @@ -12,7 +12,7 @@ describe('ng1.x compiler benchmark', function () { buttons: ['#compileWithBindings'], id: 'ng1.compile.withBindings', params: [{ - name: 'elementCount', value: 150 + name: 'elementCount', value: 150, scale: 'linear' }] }); }); @@ -23,7 +23,7 @@ describe('ng1.x compiler benchmark', function () { buttons: ['#compileNoBindings'], id: 'ng1.compile.noBindings', params: [{ - name: 'elementCount', value: 150 + name: 'elementCount', value: 150, scale: 'linear' }] }); }); diff --git a/modules/benchmarks_external/e2e_test/largetable_perf.es6 b/modules/benchmarks_external/e2e_test/largetable_perf.es6 index 82d3a22726..a14826ec49 100644 --- a/modules/benchmarks_external/e2e_test/largetable_perf.es6 +++ b/modules/benchmarks_external/e2e_test/largetable_perf.es6 @@ -24,10 +24,12 @@ describe('ng1.x largetable benchmark', function () { id: 'ng1.largetable.' + benchmarkType, params: [{ name: 'columns', - value: 100 + value: 100, + scale: 'sqrt' },{ name: 'rows', - value: 20 + value: 20, + scale: 'sqrt' },{ name: 'benchmarkType', value: benchmarkType diff --git a/modules/benchmarks_external/e2e_test/tree_perf.es6 b/modules/benchmarks_external/e2e_test/tree_perf.es6 index 90058fc805..cb19a6f5a1 100644 --- a/modules/benchmarks_external/e2e_test/tree_perf.es6 +++ b/modules/benchmarks_external/e2e_test/tree_perf.es6 @@ -12,7 +12,7 @@ describe('ng1.x tree benchmark', function () { buttons: ['#destroyDom', '#createDom'], id: 'ng1.tree', params: [{ - name: 'depth', value: 9 + name: 'depth', value: 9, scale: 'log2' }] }); }); diff --git a/modules/e2e_test_lib/e2e_test/perf_util.es6 b/modules/e2e_test_lib/e2e_test/perf_util.es6 index 1136ebe367..628864d115 100644 --- a/modules/e2e_test_lib/e2e_test/perf_util.es6 +++ b/modules/e2e_test_lib/e2e_test/perf_util.es6 @@ -7,19 +7,53 @@ module.exports = { }; function runClickBenchmark(config) { - var url = encodeURI(config.url + '?' + config.params.map(function(param) { - return param.name + '=' + param.value; - }).join('&')); - browser.get(url); - var buttons = config.buttons.map(function(selector) { - return $(selector); - }); - var benchmarkConfig = Object.create(browser.params.benchmark); - benchmarkConfig.id = browser.params.lang+'.'+config.id; - benchmarkConfig.params = config.params; - benchpress.runBenchmark(benchmarkConfig, function() { - buttons.forEach(function(button) { - button.click(); + var globalParams = browser.params; + getScaleFactor(globalParams.benchmark.scaling).then(function(scaleFactor) { + var params = config.params.map(function(param) { + return { + name: param.name, value: applyScaleFactor(param.value, scaleFactor, param.scale) + } + }); + var benchmarkConfig = Object.create(globalParams.benchmark); + benchmarkConfig.id = globalParams.lang+'.'+config.id; + benchmarkConfig.params = params; + benchmarkConfig.scaleFactor = scaleFactor; + + 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; + } } \ No newline at end of file diff --git a/protractor-perf-shared.js b/protractor-perf-shared.js index fbad40cadf..17b6f9e53e 100644 --- a/protractor-perf-shared.js +++ b/protractor-perf-shared.js @@ -27,7 +27,7 @@ config.params = { ], cloudReporter: cloudReporterConfig, scaling: [{ - browserName: /chrome/, value: 0.5 + userAgent: /Android/, value: 0.125 }] } };