2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2015-02-11 13:13:49 -05:00
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
import {StaticProvider} from '@angular/core';
|
2017-03-02 15:12:46 -05:00
|
|
|
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
2016-08-26 19:34:08 -04:00
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
import {ConsoleReporter, Injector, MeasureValues, SampleDescription} from '../../index';
|
2015-02-11 13:13:49 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('console reporter', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
let reporter: ConsoleReporter;
|
|
|
|
let log: string[];
|
2015-02-11 13:13:49 -05:00
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
function createReporter(
|
|
|
|
{columnWidth = null, sampleId = null, descriptions = null, metrics = null}: {
|
|
|
|
columnWidth?: number,
|
|
|
|
sampleId?: string,
|
|
|
|
descriptions?: {[key: string]: any}[],
|
|
|
|
metrics?: {[key: string]: any}
|
|
|
|
}) {
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!descriptions) {
|
2015-02-11 13:13:49 -05:00
|
|
|
descriptions = [];
|
|
|
|
}
|
2016-10-21 18:14:44 -04:00
|
|
|
if (sampleId == null) {
|
2015-02-11 13:13:49 -05:00
|
|
|
sampleId = 'null';
|
|
|
|
}
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
const providers: StaticProvider[] = [
|
2016-08-03 18:00:07 -04:00
|
|
|
ConsoleReporter.PROVIDERS, {
|
|
|
|
provide: SampleDescription,
|
2017-03-24 12:56:50 -04:00
|
|
|
useValue: new SampleDescription(sampleId, descriptions, metrics !)
|
2016-08-03 18:00:07 -04:00
|
|
|
},
|
2016-08-26 19:34:08 -04:00
|
|
|
{provide: ConsoleReporter.PRINT, useValue: (line: string) => log.push(line)}
|
2015-02-11 13:13:49 -05:00
|
|
|
];
|
2017-03-02 12:37:01 -05:00
|
|
|
if (columnWidth != null) {
|
2016-08-26 19:34:08 -04:00
|
|
|
providers.push({provide: ConsoleReporter.COLUMN_WIDTH, useValue: columnWidth});
|
2015-02-11 13:13:49 -05:00
|
|
|
}
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
reporter = Injector.create(providers).get(ConsoleReporter);
|
2015-02-11 13:13:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should print the sample id, description and table header', () => {
|
|
|
|
createReporter({
|
|
|
|
columnWidth: 8,
|
|
|
|
sampleId: 'someSample',
|
2015-05-27 17:57:54 -04:00
|
|
|
descriptions: [{'a': 1, 'b': 2}],
|
|
|
|
metrics: {'m1': 'some desc', 'm2': 'some other desc'}
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
expect(log).toEqual([
|
|
|
|
'BENCHMARK someSample',
|
|
|
|
'Description:',
|
|
|
|
'- a: 1',
|
|
|
|
'- b: 2',
|
|
|
|
'Metrics:',
|
|
|
|
'- m1: some desc',
|
|
|
|
'- m2: some other desc',
|
|
|
|
'',
|
|
|
|
' m1 | m2',
|
|
|
|
'-------- | --------',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should print a table row', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportMeasureValues(mv(0, 0, {'a': 1.23, 'b': 2}));
|
|
|
|
expect(log).toEqual([' 1.23 | 2.00']);
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should print the table footer and stats when there is a valid sample', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-02-11 13:13:49 -05:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
|
|
|
expect(log).toEqual(['======== | ========', '4.00+-25% | 7.50+-20%']);
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
|
2015-04-17 21:15:22 -04:00
|
|
|
it('should print the coefficient of variation only when it is meaningful', () => {
|
2015-05-27 17:57:54 -04:00
|
|
|
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
|
2015-04-17 21:15:22 -04:00
|
|
|
log = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 0}), mv(1, 1, {'a': 5, 'b': 0})]);
|
|
|
|
expect(log).toEqual(['======== | ========', '4.00+-25% | 0.00']);
|
2015-04-17 21:15:22 -04:00
|
|
|
});
|
|
|
|
|
2015-02-11 13:13:49 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:34:08 -04:00
|
|
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
2016-10-02 17:12:14 -04:00
|
|
|
return new MeasureValues(runIndex, new Date(time), values);
|
2015-02-17 17:30:24 -05:00
|
|
|
}
|