Skip to content

Commit 043b8c6

Browse files
committed
feat(bench press): add microIterations option
1 parent 03793d0 commit 043b8c6

File tree

12 files changed

+107
-38
lines changed

12 files changed

+107
-38
lines changed

modules/angular2/src/test_lib/perf_util.es6

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ function runBenchmark(config) {
2323
return getScaleFactor(browser.params.benchmark.scaling).then(function(scaleFactor) {
2424
var description = {};
2525
var urlParams = [];
26-
config.params.forEach(function(param) {
26+
var microIterations = config.microIterations || 0;
27+
var params = config.params || [];
28+
if (microIterations) {
29+
params = params.concat([{
30+
name: 'iterations', value: microIterations, scale: 'linear'
31+
}]);
32+
}
33+
params.forEach(function(param) {
2734
var name = param.name;
2835
var value = applyScaleFactor(param.value, scaleFactor, param.scale);
2936
urlParams.push(name + '=' + value);
@@ -35,6 +42,7 @@ function runBenchmark(config) {
3542
id: config.id,
3643
execute: config.work,
3744
prepare: config.prepare,
45+
microIterations: microIterations,
3846
bindings: [
3947
benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue(description)
4048
]

modules/benchmarks/e2e_test/change_detection_perf.es6

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ describe('ng2 change detection benchmark', function () {
1212
buttons: ['#ng2ChangeDetectionDynamic'],
1313
id: 'ng2.changeDetection.dynamic',
1414
params: [{
15-
name: 'numberOfChecks', value: 900000, scale: 'linear'
16-
}]
15+
name: 'numberOfChecks', value: 900000
16+
}],
17+
microIterations: 20
1718
}).then(done, done.fail);
1819
});
1920

@@ -23,8 +24,9 @@ describe('ng2 change detection benchmark', function () {
2324
buttons: ['#ng2ChangeDetectionJit'],
2425
id: 'ng2.changeDetection.jit',
2526
params: [{
26-
name: 'numberOfChecks', value: 900000, scale: 'linear'
27-
}]
27+
name: 'numberOfChecks', value: 900000
28+
}],
29+
microIterations: 20
2830
}).then(done, done.fail);
2931
});
3032

@@ -34,8 +36,9 @@ describe('ng2 change detection benchmark', function () {
3436
buttons: ['#baselineChangeDetection'],
3537
id: 'baseline.changeDetection',
3638
params: [{
37-
name: 'numberOfChecks', value: 900000, scale: 'linear'
38-
}]
39+
name: 'numberOfChecks', value: 900000
40+
}],
41+
microIterations: 20
3942
}).then(done, done.fail);
4043
});
4144

modules/benchmarks/e2e_test/di_perf.es6

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ describe('ng2 di benchmark', function () {
1313
id: 'ng2.di.getByToken',
1414
params: [{
1515
name: 'iterations', value: 20000, scale: 'linear'
16-
}]
16+
}],
17+
microIterations: 20000
1718
}).then(done, done.fail);
1819
});
1920

@@ -22,9 +23,7 @@ describe('ng2 di benchmark', function () {
2223
url: URL,
2324
buttons: ['#getByKey'],
2425
id: 'ng2.di.getByKey',
25-
params: [{
26-
name: 'iterations', value: 20000, scale: 'linear'
27-
}]
26+
microIterations: 20000
2827
}).then(done, done.fail);
2928
});
3029

@@ -33,9 +32,7 @@ describe('ng2 di benchmark', function () {
3332
url: URL,
3433
buttons: ['#getChild'],
3534
id: 'ng2.di.getChild',
36-
params: [{
37-
name: 'iterations', value: 20000, scale: 'linear'
38-
}]
35+
microIterations: 20000
3936
}).then(done, done.fail);
4037
});
4138

@@ -44,9 +41,7 @@ describe('ng2 di benchmark', function () {
4441
url: URL,
4542
buttons: ['#instantiate'],
4643
id: 'ng2.di.instantiate',
47-
params: [{
48-
name: 'iterations', value: 10000, scale: 'linear'
49-
}]
44+
microIterations: 10000
5045
}).then(done, done.fail);
5146
});
5247

modules/benchmarks/e2e_test/element_injector_perf.es6

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ describe('ng2 element injector benchmark', function () {
1111
url: URL,
1212
buttons: ['#instantiate'],
1313
id: 'ng2.elementInjector.instantiate',
14-
params: [{
15-
name: 'iterations', value: 20000, scale: 'linear'
16-
}]
14+
microIterations: 20000
1715
}).then(done, done.fail);
1816
});
1917

@@ -22,9 +20,7 @@ describe('ng2 element injector benchmark', function () {
2220
url: URL,
2321
buttons: ['#instantiateDirectives'],
2422
id: 'ng2.elementInjector.instantiateDirectives',
25-
params: [{
26-
name: 'iterations', value: 20000, scale: 'linear'
27-
}]
23+
microIterations: 20000
2824
}).then(done, done.fail);
2925
});
3026

modules/benchmarks/src/change_detection/change_detection_benchmark.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<h2>Params</h2>
66
<form>
77
Iterations:
8+
<input type="number" name="iterations" placeholder="iterations" value="20">
9+
Number of checks:
810
<input type="number" name="numberOfChecks" placeholder="numberOfChecks" value="900000">
911
<br>
1012
<button>Apply</button>

modules/benchmarks/src/change_detection/change_detection_benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ function setUpChangeDetection(changeDetection:ChangeDetection, iterations) {
138138
export function main () {
139139
BrowserDomAdapter.makeCurrent();
140140
var numberOfChecks = getIntParameter('numberOfChecks');
141+
var numberOfRuns = getIntParameter('iterations');
141142

142143
var numberOfChecksPerDetector = 10;
143-
var numberOfRuns = 20;
144144
var numberOfDetectors = numberOfChecks / numberOfChecksPerDetector / numberOfRuns;
145145

146146
setUpReflector();

modules/benchpress/src/metric/perflog_metric.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { bind, OpaqueToken } from 'angular2/di';
55

66
import { WebDriverExtension } from '../web_driver_extension';
77
import { Metric } from '../metric';
8+
import { Options } from '../sample_options';
89

910
/**
1011
* A metric that reads out the performance log
@@ -19,24 +20,36 @@ export class PerflogMetric extends Metric {
1920
_remainingEvents:List;
2021
_measureCount:int;
2122
_setTimeout:Function;
23+
_microIterations:int;
2224

23-
constructor(driverExtension:WebDriverExtension, setTimeout:Function) {
25+
/**
26+
* @param driverExtension
27+
* @param setTimeout
28+
* @param microIterations Number of iterations that run inside the browser by user code.
29+
* Used for micro benchmarks.
30+
**/
31+
constructor(driverExtension:WebDriverExtension, setTimeout:Function, microIterations:int) {
2432
super();
2533
this._driverExtension = driverExtension;
2634
this._remainingEvents = [];
2735
this._measureCount = 0;
2836
this._setTimeout = setTimeout;
37+
this._microIterations = microIterations;
2938
}
3039

3140
describe():StringMap {
32-
return {
41+
var res = {
3342
'script': 'script execution time in ms',
3443
'render': 'render time in ms',
3544
'gcTime': 'gc time in ms',
3645
'gcAmount': 'gc amount in kbytes',
3746
'gcTimeInScript': 'gc time during script execution in ms',
3847
'gcAmountInScript': 'gc amount during script execution in kbytes'
3948
};
49+
if (this._microIterations > 0) {
50+
res['scriptMicroAvg'] = 'average script time for a micro iteration';
51+
}
52+
return res;
4053
}
4154

4255
beginMeasure():Promise {
@@ -148,6 +161,9 @@ export class PerflogMetric extends Metric {
148161
}
149162
});
150163
result['script'] -= result['gcTimeInScript'];
164+
if (this._microIterations > 0) {
165+
result['scriptMicroAvg'] = result['script'] / this._microIterations;
166+
}
151167
return isPresent(markStartEvent) && isPresent(markEndEvent) ? result : null;
152168
}
153169

@@ -161,8 +177,9 @@ var _MARK_NAME_PREFIX = 'benchpress';
161177
var _SET_TIMEOUT = new OpaqueToken('PerflogMetric.setTimeout');
162178
var _BINDINGS = [
163179
bind(PerflogMetric).toFactory(
164-
(driverExtension, setTimeout) => new PerflogMetric(driverExtension, setTimeout),
165-
[WebDriverExtension, _SET_TIMEOUT]
180+
(driverExtension, setTimeout, microIterations) => new PerflogMetric(driverExtension, setTimeout, microIterations),
181+
[WebDriverExtension, _SET_TIMEOUT, Options.MICRO_ITERATIONS]
166182
),
167-
bind(_SET_TIMEOUT).toValue( (fn, millis) => PromiseWrapper.setTimeout(fn, millis) )
183+
bind(_SET_TIMEOUT).toValue( (fn, millis) => PromiseWrapper.setTimeout(fn, millis) ),
184+
bind(Options.MICRO_ITERATIONS).toValue(0)
168185
];

modules/benchpress/src/runner.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Runner {
3434
this._defaultBindings = defaultBindings;
3535
}
3636

37-
sample({id, execute, prepare, bindings}):Promise<SampleState> {
37+
sample({id, execute, prepare, microIterations, bindings}):Promise<SampleState> {
3838
var sampleBindings = [
3939
_DEFAULT_BINDINGS,
4040
this._defaultBindings,
@@ -44,6 +44,9 @@ export class Runner {
4444
if (isPresent(prepare)) {
4545
ListWrapper.push(sampleBindings, bind(Options.PREPARE).toValue(prepare));
4646
}
47+
if (isPresent(microIterations)) {
48+
ListWrapper.push(sampleBindings, bind(Options.MICRO_ITERATIONS).toValue(microIterations));
49+
}
4750
if (isPresent(bindings)) {
4851
ListWrapper.push(sampleBindings, bindings);
4952
}

modules/benchpress/src/sample_options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export class Options {
1717
static get CAPABILITIES() { return _CAPABILITIES; }
1818
// TODO(tbosch): use static initializer when our transpiler supports it
1919
static get USER_AGENT() { return _USER_AGENT; }
20+
// TODO(tbosch): use static initializer when our transpiler supports it
21+
/**
22+
* Number of iterations that run inside the browser by user code.
23+
* Used for micro benchmarks.
24+
**/
25+
static get MICRO_ITERATIONS() { return _MICRO_ITERATIONS; }
2026
}
2127

2228
var _SAMPLE_ID = new OpaqueToken('Options.sampleId');
@@ -27,3 +33,4 @@ var _PREPARE = new OpaqueToken('Options.prepare');
2733
var _EXECUTE = new OpaqueToken('Options.execute');
2834
var _CAPABILITIES = new OpaqueToken('Options.capabilities');
2935
var _USER_AGENT = new OpaqueToken('Options.userAgent');
36+
var _MICRO_ITERATIONS = new OpaqueToken('Options.microIterations');

modules/benchpress/src/sampler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ var _BINDINGS = [
136136
execute: execute,
137137
time: time
138138
}),
139-
[WebDriverAdapter, WebDriverExtension, Metric, Reporter, Validator, Options.FORCE_GC, Options.PREPARE, Options.EXECUTE, _TIME]
139+
[
140+
WebDriverAdapter, WebDriverExtension, Metric, Reporter, Validator,
141+
Options.FORCE_GC, Options.PREPARE, Options.EXECUTE, _TIME
142+
]
140143
),
141144
bind(Options.FORCE_GC).toValue(false),
142145
bind(Options.PREPARE).toValue(false),

0 commit comments

Comments
 (0)