1 window.benchmarkRunnerClient = {
6 options: { testInterval: 30000, frameRate: 50, estimatedFrameRate: true, fixTestComplexity : false },
8 _resultsDashboard: null,
11 willAddTestFrame: function (frame)
13 var main = document.querySelector("main");
14 var style = getComputedStyle(main);
15 frame.style.left = main.offsetLeft + parseInt(style.borderLeftWidth) + parseInt(style.paddingLeft) + "px";
16 frame.style.top = main.offsetTop + parseInt(style.borderTopWidth) + parseInt(style.paddingTop) + "px";
19 didRunTest: function ()
21 this.progressBar.incRange();
24 willStartFirstIteration: function ()
26 this._resultsDashboard = new ResultsDashboard();
27 this._resultsTable = new ResultsTable(document.querySelector(".results-table"), Headers);
29 this.progressBar = new ProgressBar(document.getElementById("progress-completed"), this.testsCount);
30 this.recordTable = new ResultsTable(document.querySelector(".record-table"), Headers);
33 didRunSuites: function (suitesSamplers)
35 this._resultsDashboard.push(suitesSamplers);
38 didFinishLastIteration: function ()
40 var json = this._resultsDashboard.toJSON(true, true);
41 this._resultsTable.showIterations(json[Strings["JSON_RESULTS"][0]]);
43 var element = document.querySelector("#json > textarea");
44 element.innerHTML = JSON.stringify(json[Strings["JSON_RESULTS"][0]][0], function(key, value) {
45 if (typeof value == "number")
46 return value.toFixed(2);
50 this.score = json[Strings["JSON_SCORE"]];
55 function showSection(sectionIdentifier, pushState)
57 var currentSectionElement = document.querySelector("section.selected");
58 console.assert(currentSectionElement);
60 var newSectionElement = document.getElementById(sectionIdentifier);
61 console.assert(newSectionElement);
63 currentSectionElement.classList.remove("selected");
64 newSectionElement.classList.add("selected");
67 history.pushState({section: sectionIdentifier}, document.title);
70 function startBenchmark()
72 var enabledSuites = [];
73 var checkboxes = document.querySelectorAll("#suites input");
74 for (var i = 0; i < checkboxes.length; ++i) {
75 var checkbox = checkboxes[i];
76 if (checkbox.checked) {
77 enabledSuites.push(checkbox.suite);
79 localStorage.setItem(checkbox.suite.name, +checkbox.checked);
80 localStorage.setItem("test-interval", document.getElementById("test-interval").value);
83 var enabledSuites = Suites.filter(function (suite, index) { return !suite.disabled && checkboxes[index].checked; });
84 var testsCount = enabledSuites.reduce(function (testsCount, suite) { return testsCount + suite.tests.length; }, 0);
85 benchmarkRunnerClient.testsCount = benchmarkRunnerClient.iterationCount * testsCount;
86 benchmarkRunnerClient.options["testInterval"] = parseInt(document.getElementById("test-interval").value) * 1000;
87 benchmarkRunnerClient.options["frameRate"] = parseInt(document.getElementById("frame-rate").value);
88 benchmarkRunnerClient.options["estimatedFrameRate"] = document.getElementById("estimated-frame-rate").checked;
89 benchmarkRunnerClient.options["fixTestComplexity"] = document.getElementById("fix-test-complexity").checked;
90 benchmarkRunnerClient.options["showRunningResults"] = document.getElementById("show-running-results").checked;
92 if (!benchmarkRunnerClient.options["showRunningResults"])
93 document.getElementById("record").style.display = "none";
95 var runner = new BenchmarkRunner(enabledSuites, benchmarkRunnerClient);
96 runner.runMultipleIterations(benchmarkRunnerClient.iterationCount);
101 showSection("running");
105 function showResults()
107 var element = document.querySelector("#results > h1");
108 element.textContent = Strings["TEXT_RESULTS"][0] + ":";
110 var score = benchmarkRunnerClient.score.toFixed(2);
111 element.textContent += " [Score = " + score + "]";
113 showSection("results", true);
118 var element = document.querySelector("#json > h1");
119 element.textContent = Strings["TEXT_RESULTS"][2] + ":";
121 var score = benchmarkRunnerClient.score.toFixed(2);
122 element.textContent += " [Score = " + score + "]";
124 showSection("json", true);
127 function showTestGraph(testName, axes, samples, samplingTimeOffset)
129 var element = document.querySelector("#test-graph > h1");
130 element.textContent = Strings["TEXT_RESULTS"][1] + ":";
133 element.textContent += " [test = " + testName + "]";
135 graph("#graphContainer", new Point(700, 400), new Insets(20, 50, 20, 50), axes, samples, samplingTimeOffset);
136 showSection("test-graph", true);
139 function showTestJSON(testName, testResults)
141 var element = document.querySelector("#test-json > h1");
142 element.textContent = Strings["TEXT_RESULTS"][2] + ":";
145 element.textContent += " [test = " + testName + "]";
147 var element = document.querySelector("#test-json > textarea");
148 element.innerHTML = JSON.stringify(testResults, function(key, value) {
149 if (typeof value == "number")
150 return value.toFixed(2);
154 showSection("test-json", true);
157 function populateSettings() {
158 var suitesDiv = document.getElementById("suites");
159 Suites.forEach(function(suite) {
160 var suiteDiv = document.createDocumentFragment();
162 var label = document.createElement("label");
163 var checkbox = document.createElement("input");
164 checkbox.setAttribute("type", "checkbox");
165 checkbox.suite = suite;
166 if (+localStorage.getItem(suite.name)) {
167 checkbox.checked = true;
169 label.appendChild(checkbox);
170 label.appendChild(document.createTextNode(" " + suite.name));
172 suiteDiv.appendChild(label);
173 suiteDiv.appendChild(document.createElement("br"));
174 suitesDiv.appendChild(suiteDiv);
177 var interval = localStorage.getItem("test-interval");
179 document.getElementById("test-interval").value = interval;
182 document.addEventListener("DOMContentLoaded", populateSettings);