forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
79 lines (67 loc) · 2.06 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var BenchClass = function() {
this.suites = [];
this.THREE = window.THREE ;
window.THREE = undefined;
Benchmark.options.maxTime = 1.0;
return this;
}
BenchClass.prototype.isTHREELoaded = function() {
return _.isObject(this.THREE);
}
BenchClass.prototype.newSuite = function(name) {
var s = new Benchmark.Suite(name);
this.suites.push(s);
return s;
}
BenchClass.prototype.display = function() {
for (x of this.suites) {
var s = new SuiteUI(x);
s.render();
}
}
BenchClass.prototype.warning = function(message) {
console.error(message);
}
var SuiteUI = function(suite) {
this.suite = suite;
this.isRunning = false;
return this;
}
SuiteUI.prototype.render = function() {
var n = document.importNode(this.suiteTemplate, true);
this.elem = n.querySelector("article");
this.results = n.querySelector(".results");
this.title = n.querySelector("h2");
this.runButton = n.querySelector("h3");
this.title.innerText = this.suite.name;
this.runButton.onclick = this.run.bind(this);
this.section.appendChild(n);
}
SuiteUI.prototype.run = function() {
this.runButton.click = _.noop;
this.runButton.innerText = "Running..."
this.suite.on("complete", this.complete.bind(this));
this.suite.run({
async: true
});
}
SuiteUI.prototype.complete = function() {
this.runButton.style.display = "none";
this.results.style.display = "block";
var f = _.orderBy(this.suite, ["hz"], ["desc"]);
for (var i = 0; i < f.length; i++) {
var x = f[i];
var n = document.importNode(this.suiteTestTemplate, true);
n.querySelector(".name").innerText = x.name;
n.querySelector(".ops").innerText = x.hz.toFixed();
n.querySelector(".desv").innerText = x.stats.rme.toFixed(2);
this.results.appendChild(n);
}
}
var Bench = new BenchClass();
window.addEventListener('load', function() {
SuiteUI.prototype.suiteTemplate = document.querySelector("#suite").content;
SuiteUI.prototype.suiteTestTemplate = document.querySelector("#suite-test").content;
SuiteUI.prototype.section = document.querySelector("section");
Bench.display();
})