diff --git a/benchmark/web/bp.js b/benchmark/web/bp.js index dc48360c7..57dd4b22a 100644 --- a/benchmark/web/bp.js +++ b/benchmark/web/bp.js @@ -271,9 +271,10 @@ bp.Document.addLinks = function() { [ // Add new benchmark suites here - ['tree.html', 'TreeComponent'] + ['/tree.html', 'TreeComponent'], + ['/view_factory/view_factory.html', 'ViewFactory'] ].forEach((function (link) { - linkHtml += ''+ link[1] +''; + linkHtml += ''+ link[1] +' '; })); if (linkDiv) { diff --git a/benchmark/web/view_factory/view_factory.dart b/benchmark/web/view_factory/view_factory.dart new file mode 100644 index 000000000..b8dd2c528 --- /dev/null +++ b/benchmark/web/view_factory/view_factory.dart @@ -0,0 +1,85 @@ +library angular.benchmark.compiler; + +import 'package:angular/angular.dart'; +import 'package:angular/application_factory.dart'; +import 'package:angular/mock/module.dart'; +import 'package:benchmark_harness/benchmark_harness.dart'; + +import 'dart:html'; +import 'dart:js' as js; + + +class ViewFactoryInvocaton { + ViewFactory viewFactory; + Scope scope; + DirectiveInjector di; + List elements; + + ViewFactoryInvocaton(String template) { + final injector = applicationFactory().run(); + final directiveMap = injector.get(DirectiveMap); + final compiler = injector.get(Compiler); + + elements = _getElements(template); + scope = injector.get(Scope); + di = injector.get(DirectiveInjector); + viewFactory = compiler(elements, directiveMap); + } + + run() { + viewFactory(scope, di, elements); + } + + List _getElements(String template) { + var div = new DivElement()..setInnerHtml(template, treeSanitizer: new NullTreeSanitizer()); + return new List.from(div.nodes); + } +} + +final TEMPLATE_TEXT_NO_NG_BINDING = '{{1 + 2}}' + 'left' + 'right' + ''; + +final TEMPLATE_TEXT_WITH_NG_BINDING = '{{1 + 2}}' + 'left' + 'right' + ''; + +final TEMPLATE_NO_TEXT_WITH_NG_BINDING = '' + 'left' + 'right' + ''; + +final TEMPLATE_TEXT_WITH_NG_BINDING_3_TIMES = '' + '{{1 + 2}}' + '{{1 + 2}}' + '{{1 + 2}}' + 'left' + 'right' + ''; + + +void main() { + final templates = { + "(text + ng-binding) * 3" : TEMPLATE_TEXT_WITH_NG_BINDING_3_TIMES, + "text" : TEMPLATE_TEXT_NO_NG_BINDING, + "text + ng-binding" : TEMPLATE_TEXT_WITH_NG_BINDING, + "ng-binding" : TEMPLATE_NO_TEXT_WITH_NG_BINDING + }; + + final t = document.querySelector("#templates"); + templates.keys.forEach((name) { + t.appendHtml("$name"); + }); + + viewFactory(_) { + final b = new ViewFactoryInvocaton(templates[t.value]); + int i = 5000; + while (i -- > 0) b.run(); + } + + js.context['benchmarkSteps'].add(new js.JsObject.jsify({ + "name": "ViewFactory.call", "fn": new js.JsFunction.withThis(viewFactory) + })); +} diff --git a/benchmark/web/view_factory/view_factory.html b/benchmark/web/view_factory/view_factory.html new file mode 100644 index 000000000..4b2eb43fc --- /dev/null +++ b/benchmark/web/view_factory/view_factory.html @@ -0,0 +1,138 @@ + + + + + Compilation + + + + + + + + + + + + + + + + + + Benchmark Versions: + + + + + + + Select number of samples to collect and average: + + + + + + + + + + + + Loop + Once + Loop 25x + + + + + + + + test time (ms) + + + gc time (ms) + + + garbage (KB) + + + retained memory (KB) + + + + + + + + + + + + +