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

benchmark(tree): Add transcluding components to the TreeComponent benchmark #1332

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
7 changes: 4 additions & 3 deletions benchmark/web/bp.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,21 @@ bp.Runner.runTimedTest = function (bs) {
if (typeof window.gc === 'function') {
window.gc();
}
var memory = performance.memory ? performance.memory : {usedJSHeapSize: NaN};

beforeHeap = performance.memory.usedJSHeapSize;
beforeHeap = memory.usedJSHeapSize;
startTime = bp.Measure.numMilliseconds();
bs.fn();
endTime = bp.Measure.numMilliseconds() - startTime;
afterHeap = performance.memory.usedJSHeapSize;
afterHeap = memory.usedJSHeapSize;

startGCTime = bp.Measure.numMilliseconds();
if (typeof window.gc === 'function') {
window.gc();
}
endGCTime = bp.Measure.numMilliseconds() - startGCTime;

finalHeap = performance.memory.usedJSHeapSize;
finalHeap = memory.usedJSHeapSize;
garbage = Math.abs(finalHeap - afterHeap);
retainedMemory = finalHeap - beforeHeap;
return {
Expand Down
4 changes: 4 additions & 0 deletions benchmark/web/transcluding-tree-tmpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span> {{ctrl.data.value}}
<span ng-if="ctrl.data.right != null"><transcluding-tree-url data=ctrl.data.right></span>
<span ng-if="ctrl.data.left != null"><transcluding-tree-url data=ctrl.data.left></span>
</span>
26 changes: 24 additions & 2 deletions benchmark/web/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,41 @@ import 'dart:js' as js;
'<span ng-if="ctrl.data.right != null"><tree data=ctrl.data.right></span>'
'<span ng-if="ctrl.data.left != null"><tree data=ctrl.data.left></span>'
'</span>',
publishAs: 'ctrl')
publishAs: 'ctrl',
useShadowDom: true)
class TreeComponent {
@NgOneWay('data')
var data;
}

@Component(
selector: 'transcluding-tree',
template: '<span> {{ctrl.data.value}}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about var htmlTemplate = ...; and reuse it here & above ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but SourceMetadataExtractor requires template to be a string literal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah makes sense

'<span ng-if="ctrl.data.right != null"><transcluding-tree data=ctrl.data.right></span>'
'<span ng-if="ctrl.data.left != null"><transcluding-tree data=ctrl.data.left></span>'
'</span>',
publishAs: 'ctrl',
useShadowDom: false)
class TranscludingTreeComponent extends TreeComponent {}


@Component(
selector: 'tree-url',
templateUrl: 'tree-tmpl.html',
publishAs: 'ctrl')
publishAs: 'ctrl',
useShadowDom: true)
class TreeUrlComponent {
@NgOneWay('data')
var data;
}

@Component(
selector: 'transcluding-tree-url',
templateUrl: 'transcluding-tree-tmpl.html',
publishAs: 'ctrl',
useShadowDom: false)
class TranscludingTreeUrlComponent extends TreeUrlComponent {}


// This is a baseline implementation of TreeComponent.
// It assumes the data never changes and simply throws elements on the DOM
Expand Down Expand Up @@ -250,7 +270,9 @@ main() {

var module = new Module()
..bind(TreeComponent)
..bind(TranscludingTreeComponent)
..bind(TreeUrlComponent)
..bind(TranscludingTreeUrlComponent)
..bind(NgFreeTree)
..bind(NgFreeTreeScoped)
..bind(NgFreeTreeClass)
Expand Down
9 changes: 9 additions & 0 deletions benchmark/web/tree.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<html>
<head>
<title>TreeComponent Benchmark</title>

<!-- Uncomment to test in Firefox -->
<!--<script src="packages/web_components/platform.js"></script>-->
<!--<script src="packages/web_components/dart_support.js"></script>-->

<script src="underscore.js"></script>
<script src="bp.js"></script>
<script src="tree.dart" type="application/dart"></script>
Expand Down Expand Up @@ -129,14 +134,18 @@
</p>

<div>Default: <input type=checkbox ng-model="useDefault"></div>
<div>Transcluding: <input type=checkbox ng-model="useTranscluding"></div>
<div>From URL: <input type=checkbox ng-model="useUrl"></div>
<div>Transcluding from URL: <input type=checkbox ng-model="useTranscludingFromUrl"></div>
<div>Baseline: <input type=checkbox ng-model="useBaseline"></div>
<div>Baseline + scope: <input type=checkbox ng-model="useBaselineScoped"></div>
<div>Baseline + class: <input type=checkbox ng-model="useBaselineClass"></div>


<tree ng-if="useDefault" data=initData></tree>
<transcluding-tree ng-if="useTranscluding" data=initData></transcluding-tree>
<tree-url ng-if="useUrl" data=initData></tree-url>
<transcluding-tree-url ng-if="useTranscludingFromUrl" data=initData></transcluding-tree-url>

<ng-free-tree ng-if="useBaseline" data=initData></ng-free-tree>
<ng-free-tree-scoped ng-if="useBaselineScoped" data=initData></ng-free-tree-scoped>
Expand Down