File: benchmark.js

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (79 lines) | stat: -rw-r--r-- 2,105 bytes parent folder | download | duplicates (3)
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();
})