Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Added bootstrap, scope digest, compiler and block factory benchmarks #65

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions benchmark/block_factory_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'dart:html';

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:angular/angular.dart';
import 'package:di/di.dart';

class BlockFactoryBenchmark extends BenchmarkBase {
BlockFactoryBenchmark() : super("BlockFactory");

static void main() {
new BlockFactoryBenchmark().report();
}

Injector injector;
BlockFactory blockFactory;

void run() {
blockFactory(injector);
}

void setup() {
var module = new AngularModule()
..directive(TestTranscludingDirective)
..directive(TestTemplatedComponent);
injector = new Injector([module]);
Compiler compiler = injector.get(Compiler);
StringBuffer sb = new StringBuffer();
sb.writeln('<div>');
for (int i = 0; i < 100; i++) {
sb.writeln('<div><test-templated>Hello</test-templated></div>');
sb.writeln('<div><test-transcluding><span>Transcluded Content</span>'
'</test-transcluding></div>');
}
sb.writeln('</div>');
blockFactory = compiler([new Element.html(sb.toString())]);
}

void teardown() {
injector = null;
blockFactory = null;
dumpTimerStats();
}
}

@NgDirective(transclude: true)
class TestTranscludingDirective {
TestTranscludingDirective(BoundBlockFactory blockFactory, BlockHole anchor, Scope scope) {
blockFactory(scope).insertAfter(anchor);
}
}

@NgComponent(template: '<div>Hello World!</div><content></content>')
class TestTemplatedComponent {
}

main() {
BlockFactoryBenchmark.main();
}
12 changes: 12 additions & 0 deletions benchmark/block_factory_benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>

<html>
<head>
<title>block_factory_benchmark</title>
</head>

<body>
<script type="application/dart" src="block_factory_benchmark.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions benchmark/bootstrap_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:html';

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:angular/angular.dart';
import 'package:di/di.dart';

// TODO(pavelgj): Ignore this benchmark for now because it does not give a
// good measure of the actual boostrap time, specifically the "cold start"
// of the mirrors. Look into launching boostrap benchmark in an isolate.
class BootstrapBenchmark extends BenchmarkBase {
BootstrapBenchmark() : super("Bootstrap");

static void main() {
new BootstrapBenchmark().report();
}

void run() {
var ngApp = new Element.div();
ngApp.attributes['ng-app'] = '';
ngApp.children.add(new Element.div());
query('#sandbox').children.add(ngApp);

bootstrapAngular([new AngularModule()]);

ngApp.remove();
}

void setup() {
}

void teardown() {
dumpTimerStats();
}
}

main() {
BootstrapBenchmark.main();
}
13 changes: 13 additions & 0 deletions benchmark/bootstrap_benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>

<html>
<head>
<title>module_instantiation_benchmark</title>
</head>

<body>
<div id="sandbox"></div>
<script type="application/dart" src="bootstrap_benchmark.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions benchmark/compiler_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dart:html';

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:angular/angular.dart';
import 'package:di/di.dart';

class CompilerBenchmark extends BenchmarkBase {
CompilerBenchmark() : super("Compiler");

static void main() {
new CompilerBenchmark().report();
}

Compiler compiler;

void run() {
StringBuffer sb = new StringBuffer();
sb.writeln('<div>');
for (int i = 0; i < 100; i++) {
sb.writeln('<test-transcluding><span>Transcluded Content</span></test-transcluding>');
sb.writeln('<test-templated></test-templated>');
}
sb.writeln('</div>');
compiler([new Element.html(sb.toString())]);
}

void setup() {
var module = new AngularModule()
..directive(TestTranscludingDirective)
..directive(TestTemplatedComponent);
Injector injector = new Injector([module]);
compiler = injector.get(Compiler);
}

void teardown() {
compiler = null;
dumpTimerStats();
}
}

@NgDirective(transclude: true)
class TestTranscludingDirective {
}

@NgComponent(template: '<div>Hello World!</div>')
class TestTemplatedComponent {
}

main() {
CompilerBenchmark.main();
}
12 changes: 12 additions & 0 deletions benchmark/compiler_benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>

<html>
<head>
<title>compiler_benchmark</title>
</head>

<body>
<script type="application/dart" src="compiler_benchmark.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions benchmark/ng_repeat_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:html';

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:angular/angular.dart';
import 'package:di/di.dart';

class NgRepeatBenchmark extends BenchmarkBase {
NgRepeatBenchmark() : super("NgRepeat");

static void main() {
new NgRepeatBenchmark().report();
}

Injector injector;
Scope rootScope;
BlockFactory blockFactory;

void run() {
var vals = <int>[];
for(int i = 0; i < 100; i++) {
vals.add(i);
}
Scope scope = rootScope.$new(true);
scope.vals = vals;

blockFactory(injector.createChild([new ScopeModule(scope)]));
scope.$digest();
scope.$destroy();
}

void setup() {
var module = new AngularModule();
injector = new Injector([module]);
rootScope = injector.get(Scope);
Compiler compiler = injector.get(Compiler);
String html = '<div ng-repeat="val in vals">{{i}}</div>';
blockFactory = compiler([new Element.html(html)]);
}

void teardown() {
injector = null;
rootScope = null;
blockFactory = null;
dumpTimerStats();
}
}

main() {
NgRepeatBenchmark.main();
}
12 changes: 12 additions & 0 deletions benchmark/ng_repeat_benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>

<html>
<head>
<title>ng_repeat_benchmark</title>
</head>

<body>
<script type="application/dart" src="ng_repeat_benchmark.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
46 changes: 46 additions & 0 deletions benchmark/scope_digest_benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:angular/angular.dart';
import 'package:di/di.dart';

class ScopeDigestBenchmark extends BenchmarkBase {
ScopeDigestBenchmark() : super("ScopeDigest");

static void main() {
new ScopeDigestBenchmark().report();
}

Interpolate interpolator;
Scope rootScope;

void run() {
var testScope = rootScope.$new();
// Simulating a repeater repeating a component with a simple template.
for (int i = 0; i < 100; i++) {
var childScope = testScope.$new();
childScope['hello'] = new TestObject();
childScope.$watch(interpolator('{{hello.sayHello()}}'), (_) {});
}
testScope.$digest();
testScope.$destroy();
}

void setup() {
Injector injector = new Injector([new AngularModule()]);
interpolator = injector.get(Interpolate);
rootScope = injector.get(Scope);
}

void teardown() {
interpolator = null;
rootScope = null;
dumpTimerStats();
}
}

class TestObject {
String sayHello() => 'hello';
}

main() {
ScopeDigestBenchmark.main();
}
12 changes: 12 additions & 0 deletions benchmark/scope_digest_benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>

<html>
<head>
<title>scope_digest_benchmark</title>
</head>

<body>
<script type="application/dart" src="scope_digest_benchmark.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
Loading