2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 constructor(statusCell, triggerCell, triggerLink, magicCell, summaryCell, key)
30 this._benchmarks = new Map();
31 this._statusCell = statusCell;
32 this._triggerCell = triggerCell;
33 this._triggerLink = triggerLink;
34 this._magicCell = magicCell;
35 this._summary = new Stats(summaryCell, "summary");
37 this._hadErrors = false;
42 addBenchmark(benchmark)
44 this._benchmarks.set(benchmark, new Results(benchmark));
50 this._triggerCell.addEventListener('click', this._triggerLink);
51 this._triggerCell.classList.add('ready');
58 this._triggerCell.removeEventListener('click', this._triggerLink);
59 this._triggerCell.classList.remove('ready');
65 this.disableTrigger();
66 this._updateIterations();
68 this._summary.reset();
69 for (let [benchmark, results] of this._benchmarks)
71 this._isRunning = true;
72 this._startIterations = this._numIterations = numIterations;
73 this._iterator = null;
79 this._benchmarks.get(this._benchmark).reportResult(...args);
80 this._recomputeSummary();
86 this._benchmarks.get(this._benchmark).reportError(...args);
87 this._recomputeSummary();
88 this._hadErrors = true;
104 this._sum += Math.log(value);
109 return Math.exp(this._sum * (1 / this._count));
114 for (let results of this._benchmarks.values()) {
115 for (let subResult of Results.subResults)
116 statses.push(results[subResult]);
119 let numIterations = Math.min(...statses.map(stats => stats.numIterations));
120 let data = new Array(numIterations);
121 for (let i = 0; i < data.length; ++i)
122 data[i] = new Geomean();
124 for (let stats of statses) {
125 for (let i = 0; i < data.length; ++i)
126 data[i].add(stats.valueForIteration(i));
129 let geomeans = data.map(geomean => geomean.result);
131 this._summary.reset(...geomeans);
136 this._benchmark = this._iterator ? this._iterator.next().value : null;
137 if (!this._benchmark) {
138 if (!this._numIterations) {
140 this._statusCell.innerHTML =
141 (this._hadErrors ? "Failures encountered!" : "Restart");
144 print(this._hadErrors ? "Failures encountered!" : "Success! Benchmark is now finished.");
147 this._numIterations--;
148 this._updateIterations();
149 this._iterator = this._benchmarks.keys();
150 this._benchmark = this._iterator.next().value;
153 this._benchmarks.get(this._benchmark).reportRunning();
155 let benchmark = this._benchmark;
157 window.setTimeout(() => {
158 if (!this._isRunning)
161 this._magicCell.contentDocument.body.textContent = "";
162 this._magicCell.contentDocument.body.innerHTML = "<iframe id=\"magicFrame\" frameborder=\"0\">";
164 let magicFrame = this._magicCell.contentDocument.getElementById("magicFrame");
165 magicFrame.contentDocument.open();
166 magicFrame.contentDocument.write(
167 `<!DOCTYPE html><head><title>benchmark payload</title></head><body><script>` +
168 `window.onerror = top.${this._key}.reportError;\n` +
169 `function reportResult()\n` +
171 ` var driver = top.${this._key};\n` +
172 ` driver.reportResult.apply(driver, arguments);\n` +
175 `${this._benchmark.code}</body></html>`);
178 Promise.resolve(20).then(() => {
179 if (!this._isRunning)
183 print(`Running... ${this._benchmark.name} ( ${this._numIterations + 1} to go)`);
197 this._statusCell.innerHTML = "Running Tests... " + ( this._startIterations - this._numIterations ) + "/" + this._startIterations;