Skip to content

Commit 1864f60

Browse files
committed
feat(benchmarks): Add basic dart transformer benchmarks.
Adds simple benchmarks for various transformation phases, as well as hello_world. Does not integrate these into any benchmark frameworks yet.
1 parent 457c15c commit 1864f60

File tree

9 files changed

+408
-1
lines changed

9 files changed

+408
-1
lines changed

modules/angular2/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ environment:
1111
dependencies:
1212
analyzer: '^0.24.4'
1313
barback: '^0.15.2+2'
14-
code_transformers: '^0.2.5'
14+
code_transformers: '^0.2.8'
1515
dart_style: '^0.1.3'
1616
html: '^0.12.0'
1717
logging: '>=0.9.0 <0.11.0'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library angular2.test.benchmark.transform;
2+
3+
import 'package:guinness/guinness.dart';
4+
import 'package:unittest/vm_config.dart';
5+
6+
import 'bind_generator/simple.dart' as bindGenerator;
7+
import 'directive_linker/simple.dart' as directiveLinker;
8+
import 'directive_processor/simple.dart' as directiveProcessor;
9+
import 'integration/hello_world.dart' as helloWorld;
10+
import 'reflection_remover/simple.dart' as reflectionRemover;
11+
import 'template_compiler/inline.dart' as inlineTemplateCompiler;
12+
import 'template_compiler/url.dart' as urlTemplateCompiler;
13+
14+
main() {
15+
useVMConfiguration();
16+
describe('Bind Generator Benchmark', bindGenerator.allTests);
17+
describe('Directive Linker Benchmark', directiveLinker.allTests);
18+
describe('Directive Processor Benchmark', directiveProcessor.allTests);
19+
describe('Hello World Transformer Benchmark', helloWorld.allTests);
20+
describe('Reflection Remover Benchmark', reflectionRemover.allTests);
21+
describe('Inline Template Compiler Benchmark',
22+
inlineTemplateCompiler.allTests);
23+
describe('Url Template Compiler Benchmark', urlTemplateCompiler.allTests);
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
library angular2.benchmark.transform.bind_generator.simple;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/bind_generator/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Bind Generator Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var options = new TransformerOptions(['this_is_ignored.dart']);
18+
var files = {new AssetId('a', 'a.ng_deps.dart'): aContents};
19+
var benchmark =
20+
new TransformerBenchmark([[new BindGenerator(options)]], files);
21+
print('\nRunning bind_generator benchmark...');
22+
var result = await benchmark.measure();
23+
print('Done, took ${result.round()}μs on average.');
24+
}
25+
26+
const aContents = '''
27+
library bar.ng_deps.dart;
28+
29+
import 'bar.dart';
30+
import 'package:angular2/src/core/annotations/annotations.dart';
31+
32+
bool _visited = false;
33+
void initReflector(reflector) {
34+
if (_visited) return;
35+
_visited = true;
36+
reflector
37+
..registerType(ToolTip, {
38+
'factory': () => new ToolTip(),
39+
'parameters': const [],
40+
'annotations': const [
41+
const Decorator(
42+
selector: '[tool-tip]', bind: const {'text': 'tool-tip'})
43+
]
44+
});
45+
}''';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
library angular2.benchmark.transform.directive_linker.simple;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/directive_linker/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Directive Linker Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var files = {
18+
new AssetId('a', 'a.ng_deps.dart'): aContents,
19+
new AssetId('a', 'b.ng_deps.dart'): bContents,
20+
new AssetId('a', 'c.ng_deps.dart'): cContents,
21+
};
22+
var benchmark = new TransformerBenchmark([[new DirectiveLinker()]], files);
23+
print('\nRunning directive_linker benchmark...');
24+
var result = await benchmark.measure();
25+
print('Done, took ${result.round()}μs on average.');
26+
}
27+
28+
const aContents = '''
29+
library a.ng_deps.dart;
30+
31+
import 'package:angular2/src/core/application.dart';
32+
import 'package:angular2/src/reflection/reflection_capabilities.dart';
33+
import 'b.dart';
34+
35+
bool _visited = false;
36+
void initReflector(reflector) {
37+
if (_visited) return;
38+
_visited = true;
39+
}''';
40+
41+
const bContents = '''
42+
library b.ng_deps.dart;
43+
44+
import 'b.dart';
45+
import 'package:angular2/src/core/annotations/annotations.dart';
46+
47+
bool _visited = false;
48+
void initReflector(reflector) {
49+
if (_visited) return;
50+
_visited = true;
51+
reflector
52+
..registerType(DependencyComponent, {
53+
'factory': () => new DependencyComponent(),
54+
'parameters': const [],
55+
'annotations': const [const Component(selector: '[salad]')]
56+
});
57+
}
58+
''';
59+
60+
const cContents = '''
61+
library c.ng_deps.dart;
62+
63+
import 'c.dart';
64+
import 'package:angular2/src/core/annotations/annotations.dart';
65+
import 'b.dart' as dep;
66+
67+
bool _visited = false;
68+
void initReflector(reflector) {
69+
if (_visited) return;
70+
_visited = true;
71+
reflector
72+
..registerType(MyComponent, {
73+
'factory': () => new MyComponent(),
74+
'parameters': const [],
75+
'annotations': const [
76+
const Component(
77+
selector: '[soup]', services: const [dep.DependencyComponent])
78+
]
79+
});
80+
}''';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library angular2.benchmark.transform.directive_processor.simple;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/directive_processor/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Directive Processor Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var options = new TransformerOptions(['this_is_ignored.dart']);
18+
var files = {new AssetId('a', 'a.dart'): aContents,};
19+
var benchmark =
20+
new TransformerBenchmark([[new DirectiveProcessor(options)]], files);
21+
print('\nRunning directive_processor benchmark...');
22+
var result = await benchmark.measure();
23+
print('Done, took ${result.round()}μs on average.');
24+
}
25+
26+
const aContents = '''
27+
library dinner.soup;
28+
29+
import 'package:angular2/src/core/annotations/annotations.dart';
30+
31+
@Component(selector: '[soup]')
32+
class SoupComponent {
33+
SoupComponent(@Tasty String description, @Inject(Salt) salt);
34+
}
35+
''';
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
library angular2.benchmark.transform.integration.hello_world;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Hello World Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var options = new TransformerOptions(['index.dart']);
18+
var files = {
19+
new AssetId('a', 'web/index.dart'): indexContents,
20+
new AssetId('a', 'web/index_common.dart'): indexCommonContents,
21+
};
22+
var benchmark = new TransformerBenchmark(
23+
new AngularTransformerGroup(options).phases, files);
24+
print('\nRunning hello_world benchmark...');
25+
var result = await benchmark.measure();
26+
print('Done, took ${result.round()}μs on average.');
27+
}
28+
29+
const indexContents = '''
30+
library examples.src.hello_world.index;
31+
32+
import "index_common.dart" as app;
33+
import "package:angular2/src/reflection/reflection.dart" show reflector;
34+
import "package:angular2/src/reflection/reflection_capabilities.dart"
35+
show ReflectionCapabilities;
36+
37+
main() {
38+
reflector.reflectionCapabilities = new ReflectionCapabilities();
39+
app.main();
40+
}
41+
''';
42+
43+
const indexCommonContents = '''
44+
library examples.src.hello_world.index_common;
45+
46+
import "package:angular2/angular2.dart"
47+
show bootstrap, Component, Decorator, Template, NgElement;
48+
import "package:angular2/di.dart" show Injectable;
49+
50+
@Component(selector: "hello-app", services: const [GreetingService])
51+
@Template(
52+
inline: '<div class="greeting">{{greeting}} <span red>world</span>!</div>'
53+
'<button class="changeButton" (click)="changeGreeting()">'
54+
'change greeting</button><content></content>',
55+
directives: const [RedDec])
56+
class HelloCmp {
57+
String greeting;
58+
HelloCmp(GreetingService service) {
59+
this.greeting = service.greeting;
60+
}
61+
changeGreeting() {
62+
this.greeting = "howdy";
63+
}
64+
}
65+
66+
@Decorator(selector: "[red]")
67+
class RedDec {
68+
RedDec(NgElement el) {
69+
el.domElement.style.color = "red";
70+
}
71+
}
72+
73+
@Injectable()
74+
class GreetingService {
75+
String greeting;
76+
GreetingService() {
77+
this.greeting = "hello";
78+
}
79+
}
80+
81+
main() {
82+
bootstrap(HelloCmp);
83+
}
84+
''';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library angular2.benchmark.transform.reflection_remover.simple;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/reflection_remover/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Reflection Remover Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var options = new TransformerOptions(['web/index.dart']);
18+
var files = {new AssetId('a', 'web/index.dart'): indexContents,};
19+
var benchmark =
20+
new TransformerBenchmark([[new ReflectionRemover(options)]], files);
21+
print('\nRunning reflection_remover benchmark...');
22+
var result = await benchmark.measure();
23+
print('Done, took ${result.round()}μs on average.');
24+
}
25+
26+
const indexContents = '''
27+
library web_foo;
28+
29+
import 'package:angular2/src/core/application.dart';
30+
import 'package:angular2/src/reflection/reflection.dart';
31+
import 'package:angular2/src/reflection/reflection_capabilities.dart';
32+
33+
void main() {
34+
reflector.reflectionCapabilities = new ReflectionCapabilities();
35+
bootstrap(MyComponent);
36+
}''';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
library angular2.benchmark.transform.template_compiler.inline;
2+
3+
import 'dart:async';
4+
import 'package:angular2/src/transform/common/options.dart';
5+
import 'package:angular2/src/transform/template_compiler/transformer.dart';
6+
import 'package:barback/barback.dart';
7+
import 'package:code_transformers/benchmarks.dart';
8+
import 'package:unittest/unittest.dart';
9+
10+
Future main() => runBenchmark();
11+
12+
allTests() {
13+
test('Inline Template Compiler Benchmark Runs', runBenchmark);
14+
}
15+
16+
Future runBenchmark() async {
17+
var options = new TransformerOptions(['index.dart']);
18+
var files = {new AssetId('a', 'web/a.ng_deps.dart'): aContents,};
19+
var benchmark =
20+
new TransformerBenchmark([[new TemplateCompiler(options)]], files);
21+
print('\nRunning template_compiler inline benchmark...');
22+
var result = await benchmark.measure();
23+
print('Done, took ${result.round()}μs on average.');
24+
}
25+
26+
const aContents = '''
27+
library examples.src.hello_world.index_common_dart;
28+
29+
import 'hello.dart';
30+
import 'package:angular2/angular2.dart'
31+
show bootstrap, Component, Decorator, Template, NgElement;
32+
33+
bool _visited = false;
34+
void initReflector(reflector) {
35+
if (_visited) return;
36+
_visited = true;
37+
reflector
38+
..registerType(HelloCmp, {
39+
'factory': () => new HelloCmp(),
40+
'parameters': const [const []],
41+
'annotations': const [
42+
const Component(selector: 'hello-app'),
43+
const Template(
44+
inline: '<button (click)="action()">go</button>{{greeting}}')
45+
]
46+
});
47+
}
48+
''';

0 commit comments

Comments
 (0)