Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <sky> | |
| 2 <import src="../resources/runner.sky" as="PerfRunner" /> | |
| 3 <script> | |
| 4 var sky = document.documentElement; | |
|
ojan
2014/11/11 01:41:37
document.querySelector('sky') ?
We're going to be
esprehn
2014/11/11 01:44:52
We're going to remove querySelector also, so all t
| |
| 5 | |
| 6 var widgets = 0; | |
| 7 var basicElements = 0; | |
| 8 var texts = 0; | |
| 9 | |
| 10 var WidgetPrototype = Object.create(HTMLElement.prototype); | |
| 11 WidgetPrototype.createdCallback = function() { | |
| 12 widgets++; | |
| 13 this.wasCreated = true; | |
| 14 this.wasAttached = false; | |
| 15 this.wasDetached = false; | |
| 16 this.attrsChanged = []; | |
| 17 this.createShadowRoot(); | |
| 18 }; | |
| 19 | |
| 20 WidgetPrototype.attachedCallback = function() { | |
| 21 this.wasAttached = true; | |
|
ojan
2014/11/11 01:41:37
indentation
| |
| 22 }; | |
| 23 | |
| 24 WidgetPrototype.detachedCallback = function() { | |
| 25 this.wasDetached = true; | |
|
ojan
2014/11/11 01:41:37
ditto
| |
| 26 }; | |
| 27 | |
| 28 WidgetPrototype.attributeChangedCallback = function(name, oldValue, newValue) { | |
| 29 this.attrsChanged.push({ | |
| 30 name: name, | |
| 31 oldValue: oldValue, | |
| 32 newValue: newValue, | |
| 33 }); | |
| 34 }; | |
| 35 | |
| 36 var Widget = document.registerElement("x-widget", { | |
| 37 prototype: WidgetPrototype, | |
| 38 }); | |
| 39 | |
| 40 function createElement(tagName) { | |
| 41 basicElements++; | |
| 42 return document.createElement(tagName); | |
| 43 } | |
| 44 | |
| 45 function createText(text) { | |
| 46 texts++; | |
| 47 return document.createTextNode(text); | |
| 48 } | |
| 49 | |
| 50 function createElements(root, depth) { | |
| 51 for (var i = 0; i < 4; i++) { | |
| 52 var div = createElement("div"); | |
| 53 var span1 = div.appendChild(createElement("span")); | |
| 54 span1.appendChild(createText("foo")); | |
| 55 span1.setAttribute("id", "span" + (i * depth)); | |
| 56 div.appendChild(createText(" ")); | |
| 57 div.setAttribute("class", "b" + i + " a" + i); | |
| 58 var span2 = div.appendChild(createElement("span")); | |
| 59 span2.appendChild(createText("bar")); | |
| 60 var widget = span2.appendChild(new Widget()); | |
| 61 widget.setAttribute("id", "widget-" + (i * depth)); | |
| 62 widget.setAttribute("custom", "example attribute"); | |
| 63 widget.setAttribute("custom2", "example attribute2"); | |
| 64 root.appendChild(div); | |
| 65 if (depth) | |
| 66 createElements(widget.shadowRoot, depth - 1); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 var runner = new PerfRunner({ | |
| 71 setup: function() { | |
| 72 widgets = 0; | |
| 73 basicElements = 0; | |
| 74 texts = 0; | |
| 75 }, | |
| 76 iterations: 10, | |
| 77 unit: "ms", | |
| 78 }); | |
| 79 | |
| 80 runner.runAsync(function(done) { | |
| 81 var root = createElement("div"); | |
| 82 sky.appendChild(root); | |
| 83 createElements(root, 3); | |
| 84 root.remove(); | |
| 85 // console.log("widgets: " + widgets); | |
|
ojan
2014/11/11 01:41:37
Did you mean to include these?
esprehn
2014/11/11 01:44:52
Yes, that way you can see how much DOM is actually
| |
| 86 // console.log("basic elements: " + basicElements); | |
| 87 // console.log("texts: " + texts); | |
| 88 // CONSOLE: LOG: widgets: 340 | |
| 89 // CONSOLE: LOG: basic elements: 1021 | |
| 90 // CONSOLE: LOG: texts: 1020 | |
| 91 done(); | |
| 92 }); | |
| 93 </script> | |
| 94 </sky> | |
| OLD | NEW |