Files
Angular-Docs-Cn/modules/benchpress/src/runner.js
T
Tobias Bosch 21a293b017 refactor(bench press): rename metrics and adapt them to the features of the browser
* Rename metrics, add `Time` suffix to all so that they are
  more consistent
* iOS does not give us `gc` metrics, so they should not be reported
* Rename `scriptMicroAvg` into `microScriptTimeAvg`
* Rename previous `script` metric into `pureScriptTime` metric,
  and keep `scriptTime` metric as the overall time, so that we still
  have a shared metric across devices independent of the supported
  browser features
* `microScriptTimeAvg` is now based on overall `scriptTime`, including
  gc and render time.
* Move more shared DI tokens into `common_options` (previously
  `sample_options`).

Closes #930
2015-03-13 20:46:37 -07:00

83 lines
3.0 KiB
JavaScript

import { Injector, bind } from 'angular2/di';
import { isPresent, isBlank } from 'angular2/src/facade/lang';
import { List, ListWrapper } from 'angular2/src/facade/collection';
import { Promise } from 'angular2/src/facade/async';
import { Sampler, SampleState } from './sampler';
import { ConsoleReporter } from './reporter/console_reporter';
import { MultiReporter } from './reporter/multi_reporter';
import { RegressionSlopeValidator } from './validator/regression_slope_validator';
import { SizeValidator } from './validator/size_validator';
import { Validator } from './validator';
import { PerflogMetric } from './metric/perflog_metric';
import { MultiMetric } from './metric/multi_metric';
import { ChromeDriverExtension } from './webdriver/chrome_driver_extension';
import { IOsDriverExtension } from './webdriver/ios_driver_extension';
import { WebDriverExtension } from './web_driver_extension';
import { SampleDescription } from './sample_description';
import { WebDriverAdapter } from './web_driver_adapter';
import { Reporter } from './reporter';
import { Metric } from './metric';
import { Options } from './common_options';
/**
* The Runner is the main entry point for executing a sample run.
* It provides defaults, creates the injector and calls the sampler.
*/
export class Runner {
_defaultBindings:List;
constructor(defaultBindings:List = null) {
if (isBlank(defaultBindings)) {
defaultBindings = [];
}
this._defaultBindings = defaultBindings;
}
sample({id, execute, prepare, microIterations, bindings}):Promise<SampleState> {
var sampleBindings = [
_DEFAULT_BINDINGS,
this._defaultBindings,
bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute)
];
if (isPresent(prepare)) {
ListWrapper.push(sampleBindings, bind(Options.PREPARE).toValue(prepare));
}
if (isPresent(microIterations)) {
ListWrapper.push(sampleBindings, bind(Options.MICRO_ITERATIONS).toValue(microIterations));
}
if (isPresent(bindings)) {
ListWrapper.push(sampleBindings, bindings);
}
return new Injector(sampleBindings).asyncGet(Sampler)
.then( (sampler) => sampler.sample() );
}
}
var _DEFAULT_BINDINGS = [
Options.DEFAULT_BINDINGS,
Sampler.BINDINGS,
ConsoleReporter.BINDINGS,
RegressionSlopeValidator.BINDINGS,
SizeValidator.BINDINGS,
ChromeDriverExtension.BINDINGS,
IOsDriverExtension.BINDINGS,
PerflogMetric.BINDINGS,
SampleDescription.BINDINGS,
MultiReporter.createBindings([ConsoleReporter]),
MultiMetric.createBindings([PerflogMetric]),
Reporter.bindTo(MultiReporter),
Validator.bindTo(RegressionSlopeValidator),
WebDriverExtension.bindTo([ChromeDriverExtension, IOsDriverExtension]),
Metric.bindTo(MultiMetric),
bind(Options.CAPABILITIES).toAsyncFactory(
(adapter) => adapter.capabilities(), [WebDriverAdapter]
),
bind(Options.USER_AGENT).toAsyncFactory(
(adapter) => adapter.executeScript('return window.navigator.userAgent;'), [WebDriverAdapter]
)
];