Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: sky/benchmarks/dom/creation.sky

Issue 713973003: Add a basic benchmark for creating DOM. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: ojan review. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <sky>
2 <import src="../resources/runner.sky" as="PerfRunner" />
3 <script>
4 var sky = document.querySelector("sky");
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;
22 };
23
24 WidgetPrototype.detachedCallback = function() {
25 this.wasDetached = true;
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);
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>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698