1 ResultsDashboard = Utilities.createClass(
4 this._iterationsSamplers = [];
5 this._processedData = undefined;
8 push: function(suitesSamplers)
10 this._iterationsSamplers.push(suitesSamplers);
13 _processData: function()
15 var iterationsResults = [];
16 var iterationsScores = [];
18 this._iterationsSamplers.forEach(function(iterationSamplers, index) {
19 var suitesResults = {};
20 var suitesScores = [];
22 for (var suiteName in iterationSamplers) {
23 var suite = suiteFromName(suiteName);
24 var suiteSamplerData = iterationSamplers[suiteName];
26 var testsResults = {};
29 for (var testName in suiteSamplerData) {
30 testsResults[testName] = suiteSamplerData[testName];
31 testsScores.push(testsResults[testName][Strings.json.score]);
34 suitesResults[suiteName] = {};
35 suitesResults[suiteName][Strings.json.score] = Statistics.geometricMean(testsScores);
36 suitesResults[suiteName][Strings.json.results.tests] = testsResults;
37 suitesScores.push(suitesResults[suiteName][Strings.json.score]);
40 iterationsResults[index] = {};
41 iterationsResults[index][Strings.json.score] = Statistics.geometricMean(suitesScores);
42 iterationsResults[index][Strings.json.results.suites] = suitesResults;
43 iterationsScores.push(iterationsResults[index][Strings.json.score]);
46 this._processedData = {};
47 this._processedData[Strings.json.score] = Statistics.sampleMean(iterationsScores.length, iterationsScores.reduce(function(a, b) { return a * b; }));
48 this._processedData[Strings.json.results.iterations] = iterationsResults;
53 if (this._processedData)
54 return this._processedData;
56 return this._processedData;
61 return this.data[Strings.json.score];
65 ResultsTable = Utilities.createClass(
66 function(element, headers)
68 this.element = element;
69 this._headers = headers;
71 this._flattenedHeaders = [];
72 this._headers.forEach(function(header) {
77 this._flattenedHeaders = this._flattenedHeaders.concat(header.children);
79 this._flattenedHeaders.push(header);
82 this._flattenedHeaders = this._flattenedHeaders.filter(function (header) {
83 return !header.disabled;
91 this.element.innerHTML = "";
94 _addHeader: function()
96 var thead = Utilities.createElement("thead", {}, this.element);
97 var row = Utilities.createElement("tr", {}, thead);
99 this._headers.forEach(function (header) {
103 var th = Utilities.createElement("th", {}, row);
104 if (header.title != Strings.text.graph)
105 th.textContent = header.title;
107 th.colSpan = header.children.length;
111 _addEmptyRow: function()
113 var row = Utilities.createElement("tr", {}, this.element);
114 this._flattenedHeaders.forEach(function (header) {
115 return Utilities.createElement("td", { class: "suites-separator" }, row);
119 _addTest: function(testName, testResults, options)
121 var row = Utilities.createElement("tr", {}, this.element);
123 this._flattenedHeaders.forEach(function (header) {
124 var td = Utilities.createElement("td", {}, row);
125 if (header.title == Strings.text.testName) {
126 td.textContent = testName;
127 } else if (header.text) {
128 var data = testResults[header.text];
129 if (typeof data == "number")
130 data = data.toFixed(2);
131 td.textContent = data;
136 _addSuite: function(suiteName, suiteResults, options)
138 for (var testName in suiteResults[Strings.json.results.tests]) {
139 var testResults = suiteResults[Strings.json.results.tests][testName];
140 this._addTest(testName, testResults, options);
144 _addIteration: function(iterationResult, options)
146 for (var suiteName in iterationResult[Strings.json.results.suites]) {
148 this._addSuite(suiteName, iterationResult[Strings.json.results.suites][suiteName], options);
152 showIterations: function(iterationsResults, options)
157 iterationsResults.forEach(function(iterationResult) {
158 this._addIteration(iterationResult, options);
163 window.benchmarkRunnerClient = {
168 initialize: function(suites, options)
170 this.options = options;
173 willStartFirstIteration: function()
175 this.results = new ResultsDashboard();
178 didRunSuites: function(suitesSamplers)
180 this.results.push(suitesSamplers);
183 didFinishLastIteration: function()
185 benchmarkController.showResults();
189 window.sectionsManager =
191 showSection: function(sectionIdentifier, pushState)
193 var currentSectionElement = document.querySelector("section.selected");
194 console.assert(currentSectionElement);
196 var newSectionElement = document.getElementById(sectionIdentifier);
197 console.assert(newSectionElement);
199 currentSectionElement.classList.remove("selected");
200 newSectionElement.classList.add("selected");
203 history.pushState({section: sectionIdentifier}, document.title);
206 setSectionScore: function(sectionIdentifier, score, mean)
208 document.querySelector("#" + sectionIdentifier + " .score").textContent = score;
210 document.querySelector("#" + sectionIdentifier + " .mean").innerHTML = mean;
213 populateTable: function(tableIdentifier, headers, data)
215 var table = new ResultsTable(document.getElementById(tableIdentifier), headers);
216 table.showIterations(data, benchmarkRunnerClient.options);
220 window.benchmarkController = {
221 _startBenchmark: function(suites, options, frameContainerID)
223 benchmarkRunnerClient.initialize(suites, options);
224 var frameContainer = document.getElementById(frameContainerID);
225 var runner = new BenchmarkRunner(suites, frameContainer, benchmarkRunnerClient);
226 runner.runMultipleIterations();
228 sectionsManager.showSection("test-container");
231 startBenchmark: function()
235 "display": "minimal",
236 "adjustment": "adaptive",
238 "kalman-process-error": 1,
239 "kalman-measurement-error": 4,
240 "time-measurement": "performance"
242 this._startBenchmark(Suites, options, "test-container");
245 showResults: function()
247 if (!this.addedKeyEvent) {
248 document.addEventListener("keypress", this.selectResults, false);
249 this.addedKeyEvent = true;
252 sectionsManager.setSectionScore("results", benchmarkRunnerClient.results.score.toFixed(2));
253 var data = benchmarkRunnerClient.results.data[Strings.json.results.iterations];
254 sectionsManager.populateTable("results-header", Headers.testName, data);
255 sectionsManager.populateTable("results-score", Headers.score, data);
256 sectionsManager.showSection("results", true);
259 selectResults: function(event)
261 if (event.charCode != 115) // 's'
264 event.target.selectRange = ((event.target.selectRange || 0) + 1) % 3;
266 var selection = window.getSelection();
267 selection.removeAllRanges();
268 var range = document.createRange();
269 switch (event.target.selectRange) {
271 range.setStart(document.querySelector("#results .score"), 0);
272 range.setEndAfter(document.querySelector("#results-score > tr:last-of-type"), 0);
276 range.selectNodeContents(document.querySelector("#results .score"));
280 range.selectNode(document.getElementById("results-score"));
284 selection.addRange(range);