Remove sky/benchmarks
These benchmarks are very out-dated. In fact, they're still written in JavaScript and mostly test the performance of the DOM. TBR=eseidel@chromium.org Review URL: https://codereview.chromium.org/1216823002.
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
<sky>
|
||||
<import src="../resources/runner.sky" as="PerfRunner" />
|
||||
<script>
|
||||
var sky = document.querySelector("sky");
|
||||
|
||||
var widgets = 0;
|
||||
var basicElements = 0;
|
||||
var texts = 0;
|
||||
|
||||
var WidgetPrototype = Object.create(HTMLElement.prototype);
|
||||
WidgetPrototype.createdCallback = function() {
|
||||
widgets++;
|
||||
this.wasCreated = true;
|
||||
this.wasAttached = false;
|
||||
this.wasDetached = false;
|
||||
this.attrsChanged = [];
|
||||
this.ensureShadowRoot();
|
||||
};
|
||||
|
||||
WidgetPrototype.attachedCallback = function() {
|
||||
this.wasAttached = true;
|
||||
};
|
||||
|
||||
WidgetPrototype.detachedCallback = function() {
|
||||
this.wasDetached = true;
|
||||
};
|
||||
|
||||
WidgetPrototype.attributeChangedCallback = function(name, oldValue, newValue) {
|
||||
this.attrsChanged.push({
|
||||
name: name,
|
||||
oldValue: oldValue,
|
||||
newValue: newValue,
|
||||
});
|
||||
};
|
||||
|
||||
var Widget = document.registerElement("x-widget", {
|
||||
prototype: WidgetPrototype,
|
||||
});
|
||||
|
||||
function createElement(tagName) {
|
||||
basicElements++;
|
||||
return document.createElement(tagName);
|
||||
}
|
||||
|
||||
function createText(text) {
|
||||
texts++;
|
||||
return new Text(text);
|
||||
}
|
||||
|
||||
function createElements(root, depth) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var div = createElement("div");
|
||||
var span1 = div.appendChild(createElement("span"));
|
||||
span1.appendChild(createText("foo"));
|
||||
span1.setAttribute("id", "span" + (i * depth));
|
||||
div.appendChild(createText(" "));
|
||||
div.setAttribute("class", "b" + i + " a" + i);
|
||||
var span2 = div.appendChild(createElement("span"));
|
||||
span2.appendChild(createText("bar"));
|
||||
var widget = span2.appendChild(new Widget());
|
||||
widget.setAttribute("id", "widget-" + (i * depth));
|
||||
widget.setAttribute("custom", "example attribute");
|
||||
widget.setAttribute("custom2", "example attribute2");
|
||||
root.appendChild(div);
|
||||
if (depth)
|
||||
createElements(widget.shadowRoot, depth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
var runner = new PerfRunner({
|
||||
setup: function() {
|
||||
widgets = 0;
|
||||
basicElements = 0;
|
||||
texts = 0;
|
||||
},
|
||||
iterations: 10,
|
||||
unit: "ms",
|
||||
});
|
||||
|
||||
runner.runAsync(function(done) {
|
||||
var root = createElement("div");
|
||||
sky.appendChild(root);
|
||||
createElements(root, 3);
|
||||
root.remove();
|
||||
// console.log("widgets: " + widgets);
|
||||
// console.log("basic elements: " + basicElements);
|
||||
// console.log("texts: " + texts);
|
||||
// CONSOLE: LOG: widgets: 340
|
||||
// CONSOLE: LOG: basic elements: 1021
|
||||
// CONSOLE: LOG: texts: 1020
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
</sky>
|
||||
@@ -1,44 +0,0 @@
|
||||
<sky>
|
||||
<import src="../resources/runner.sky" as="PerfRunner" />
|
||||
<style>
|
||||
div {
|
||||
height: 10px;
|
||||
}
|
||||
span {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
<div id='content'></div>
|
||||
<script>
|
||||
var content = document.getElementById('content');
|
||||
|
||||
var out = [];
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(document.createElement('span')).appendChild(new Text('foo'));
|
||||
div.appendChild(new Text(' '));
|
||||
div.appendChild(document.createElement('span')).appendChild(new Text('bar'));
|
||||
content.appendChild(div);
|
||||
}
|
||||
|
||||
var b = document.querySelector('sky');
|
||||
|
||||
var runner = new PerfRunner({
|
||||
setup: function() {
|
||||
b.style.width = '210px';
|
||||
getComputedStyle(b).color;
|
||||
b.offsetHeight;
|
||||
|
||||
b.style.width = '200px';
|
||||
getComputedStyle(b).color;
|
||||
},
|
||||
iterations: 10,
|
||||
unit: 'ms',
|
||||
});
|
||||
|
||||
runner.runAsync(function(done) {
|
||||
b.offsetHeight;
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
</sky>
|
||||
@@ -1,22 +0,0 @@
|
||||
<import src="../resources/runner.sky" as="PerfRunner" />
|
||||
<script>
|
||||
var specURL = "resources/html5.html";
|
||||
var cacheBust = 100;
|
||||
|
||||
var runner = new PerfRunner({
|
||||
iterations: 10,
|
||||
unit: 'ms',
|
||||
});
|
||||
|
||||
runner.runAsync(function(done) {
|
||||
var element = document.createElement("import");
|
||||
|
||||
element.addEventListener("load", function() {
|
||||
element.remove();
|
||||
done();
|
||||
});
|
||||
|
||||
element.setAttribute("src", specURL + "?cacheBust=" + cacheBust++);
|
||||
document.documentElement.appendChild(element);
|
||||
});
|
||||
</script>
|
||||
@@ -1,160 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
void assertHasParentNode(Node n) { assert(n.parentNode != null); }
|
||||
void assertHasParentNodes(List<Node> list) {
|
||||
for (var n in list) {
|
||||
assertHasParentNode(n);
|
||||
}
|
||||
}
|
||||
|
||||
class Node {
|
||||
|
||||
ParentNode parentNode;
|
||||
Node nextSibling;
|
||||
Node previousSibling;
|
||||
Node();
|
||||
|
||||
void insertBefore(List<Node> nodes) {
|
||||
int count = nodes.length;
|
||||
while (count-- > 0) {
|
||||
parentNode._insertBefore(nodes[count], this);
|
||||
}
|
||||
|
||||
assertHasParentNodes(nodes);
|
||||
}
|
||||
|
||||
remove() {
|
||||
if (parentNode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextSibling != null) {
|
||||
nextSibling.previousSibling = previousSibling;
|
||||
} else {
|
||||
parentNode.lastChild = previousSibling;
|
||||
}
|
||||
|
||||
if (previousSibling != null) {
|
||||
previousSibling.nextSibling = nextSibling;
|
||||
} else {
|
||||
parentNode.firstChild = nextSibling;
|
||||
}
|
||||
|
||||
parentNode = null;
|
||||
nextSibling = null;
|
||||
previousSibling = null;
|
||||
}
|
||||
}
|
||||
|
||||
class Text extends Node {
|
||||
String data;
|
||||
Text(this.data) : super();
|
||||
}
|
||||
|
||||
class ParentNode extends Node {
|
||||
Node firstChild;
|
||||
Node lastChild;
|
||||
|
||||
ParentNode() : super();
|
||||
|
||||
Node setChild(Node node) {
|
||||
firstChild = node;
|
||||
lastChild = node;
|
||||
node.parentNode = this;
|
||||
assertHasParentNode(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
Node _insertBefore(Node node, Node ref) {
|
||||
assert(ref == null || ref.parentNode == this);
|
||||
|
||||
if (node.parentNode != null) {
|
||||
node.remove();
|
||||
}
|
||||
|
||||
node.parentNode = this;
|
||||
|
||||
if (firstChild == null && lastChild == null) {
|
||||
firstChild = node;
|
||||
lastChild = node;
|
||||
} else if (ref == null) {
|
||||
node.previousSibling = lastChild;
|
||||
lastChild.nextSibling = node;
|
||||
lastChild = node;
|
||||
} else {
|
||||
if (ref == firstChild) {
|
||||
assert(ref.previousSibling == null);
|
||||
firstChild = node;
|
||||
}
|
||||
node.previousSibling = ref.previousSibling;
|
||||
ref.previousSibling = node;
|
||||
node.nextSibling = ref;
|
||||
}
|
||||
|
||||
assertHasParentNode(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
Node appendChild(Node node) {
|
||||
return _insertBefore(node, null);
|
||||
}
|
||||
}
|
||||
|
||||
class Element extends ParentNode {
|
||||
void addEventListener(String type, EventListener listener, [bool useCapture = false]) {}
|
||||
void removeEventListener(String type, EventListener listener) {}
|
||||
void setAttribute(String name, [String value]) {}
|
||||
}
|
||||
|
||||
class Document extends ParentNode {
|
||||
Document();
|
||||
Element createElement(String tagName) {
|
||||
switch (tagName) {
|
||||
case 'img' : return new HTMLImageElement();
|
||||
default : return new Element();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HTMLImageElement extends Element {
|
||||
HTMLImageElement();
|
||||
String src;
|
||||
Object style = {};
|
||||
}
|
||||
|
||||
class Event {}
|
||||
|
||||
class PointerEvent extends Event {}
|
||||
class GestureEvent extends Event {}
|
||||
class WheelEvent extends Event {}
|
||||
|
||||
typedef EventListener(Event event);
|
||||
|
||||
void _callRAF(Function fn) {
|
||||
fn(new DateTime.now().millisecondsSinceEpoch.toDouble());
|
||||
}
|
||||
|
||||
class Window {
|
||||
int requestAnimationFrame(Function fn) {
|
||||
new Timer(const Duration(milliseconds: 16), () {
|
||||
_callRAF(fn);
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
||||
void cancelAnimationFrame(int id) {
|
||||
}
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
Window window = new Window();
|
||||
|
||||
class ClientRect {
|
||||
double top;
|
||||
double right;
|
||||
double bottomr;
|
||||
double left;
|
||||
double width;
|
||||
double height;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<script>
|
||||
function PerfRunner(options) {
|
||||
this.unit_ = options.unit || "ms";
|
||||
this.iterationsRemaining_ = options.iterations || 10;
|
||||
this.results_ = [];
|
||||
this.setup_ = options.setup;
|
||||
this.logLines_ = [];
|
||||
}
|
||||
|
||||
PerfRunner.prototype.log = function(line) {
|
||||
this.logLines_.push(line);
|
||||
};
|
||||
|
||||
PerfRunner.prototype.recordResult = function(result) {
|
||||
this.results_.push(result);
|
||||
};
|
||||
|
||||
PerfRunner.prototype.runAsync = function(test) {
|
||||
var self = this;
|
||||
window.setTimeout(function() {
|
||||
if (self.setup_) {
|
||||
var setup = self.setup_;
|
||||
setup();
|
||||
}
|
||||
|
||||
var startTime = Date.now();
|
||||
test(function() {
|
||||
var endTime = Date.now();
|
||||
|
||||
self.recordResult(endTime - startTime);
|
||||
if (--self.iterationsRemaining_ > 0)
|
||||
self.runAsync(test);
|
||||
else
|
||||
self.finish();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
PerfRunner.prototype.computeStatistics = function() {
|
||||
var data = this.results_.slice();
|
||||
|
||||
// Add values from the smallest to the largest to avoid the loss of significance
|
||||
data.sort(function(a, b) { return a - b; });
|
||||
|
||||
var middle = Math.floor(data.length / 2);
|
||||
var stats = {
|
||||
min: data[0],
|
||||
max: data[data.length - 1],
|
||||
median: data.length % 2 ? data[middle] : (data[middle - 1] + data[middle]) / 2,
|
||||
};
|
||||
|
||||
// Compute the mean and variance using Knuth's online algorithm (has good numerical stability).
|
||||
var squareSum = 0;
|
||||
stats.values = this.results_;
|
||||
stats.mean = 0;
|
||||
for (var i = 0; i < data.length; ++i) {
|
||||
var x = data[i];
|
||||
var delta = x - stats.mean;
|
||||
var sweep = i + 1.0;
|
||||
stats.mean += delta / sweep;
|
||||
squareSum += delta * (x - stats.mean);
|
||||
}
|
||||
stats.variance = data.length <= 1 ? 0 : squareSum / (data.length - 1);
|
||||
stats.stdev = Math.sqrt(stats.variance);
|
||||
stats.unit = this.unit_;
|
||||
|
||||
return stats;
|
||||
};
|
||||
|
||||
PerfRunner.prototype.logStatistics = function(title) {
|
||||
var stats = this.computeStatistics();
|
||||
this.log("");
|
||||
this.log(title);
|
||||
if (stats.values)
|
||||
this.log("values " + stats.values.join(", ") + " " + stats.unit);
|
||||
this.log("avg " + stats.mean + " " + stats.unit);
|
||||
this.log("median " + stats.median + " " + stats.unit);
|
||||
this.log("stdev " + stats.stdev + " " + stats.unit);
|
||||
this.log("min " + stats.min + " " + stats.unit);
|
||||
this.log("max " + stats.max + " " + stats.unit);
|
||||
};
|
||||
|
||||
PerfRunner.prototype.finish = function () {
|
||||
this.logStatistics("Time:");
|
||||
internals.notifyTestComplete(this.logLines_.join('\n'));
|
||||
}
|
||||
|
||||
module.exports = PerfRunner;
|
||||
</script>
|
||||
Reference in New Issue
Block a user