forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharness.js
388 lines (346 loc) · 14.9 KB
/
harness.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
* Copyright (C) 2011, 2012 Purdue University
* Written by Gregor Richards
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
(function() {
// put benchmarks here
var benchmarks = ["amazon-chrome", "amazon-chrome-win", "amazon-firefox",
"amazon-firefox-win", "amazon-safari", "facebook-chrome",
"facebook-chrome-win", "facebook-firefox",
"facebook-firefox-win", "facebook-safari",
"google-chrome", "google-chrome-win", "google-firefox",
"google-firefox-win", "google-safari", "twitter-chrome",
"twitter-chrome-win", "twitter-firefox",
"twitter-firefox-win", "twitter-safari", "yahoo-chrome",
"yahoo-chrome-win", "yahoo-firefox", "yahoo-firefox-win",
"yahoo-safari"];
var modes = {
"*": ["urem"],
"amazon-firefox": ["urm"],
"amazon-firefox-win": ["urm"],
"google-firefox": ["uem"],
"twitter-chrome-win": ["rem"]
};
var minRuns = 23;
var keepRuns = 20;
var maxRuns = 100;
var maxCIM = 0.10;
// fixups for old engines
if (!Array.prototype.reduce) {
Array.prototype.reduce = function(f, val) {
for (var i = 0; i < this.length; i++) {
val = f(val, this[i]);
}
return val;
};
}
// all test results
var results = {};
var curRun = 0;
var curBenchmark = 0;
var curMode = 0;
function getModes(bm) {
if (bm in modes) return modes[bm];
return modes["*"];
}
// call this to either rerun or go to another page and come back
function rerun() {
try {
if (window.sessionStorage) {
// store this for the session and go 'round to another page to force uncaching on Chrome
sessionStorage.JSBNG_harnessState = JSON.stringify({
results: results,
curRun: curRun,
curBenchmark: curBenchmark,
curMode: curMode
});
window.location.href = window.location.href.replace(/\/[^\/]*$/, "/reload.html");
return;
}
} catch (ex) {}
runBenchmark();
}
// load our current state and run
function onload() {
var gob = document.getElementById("go");
try {
if (window.sessionStorage && "JSBNG_harnessState" in sessionStorage) {
var state = JSON.parse(sessionStorage.JSBNG_harnessState);
results = state.results;
curRun = state.curRun;
curBenchmark = state.curBenchmark;
curMode = state.curMode;
setTimeout(runBenchmark, 200);
gob.style.display = "none";
return;
}
} catch (ex) {}
gob.onclick = function() {
gob.style.display = "none";
setTimeout(runBenchmark, 200);
};
if (/#run/.test(window.location.href)) {
gob.style.display = "none";
setTimeout(runBenchmark, 200);
}
}
function runBenchmark() {
var output = document.getElementById("output");
var bmframe = document.getElementById("bmframe");
// should we stop?
if (curRun < minRuns) {
output.innerHTML = (curRun+1) + "/" + minRuns;
} else {
// check if our S/M is OK
var stats = handleResults(false);
output.innerHTML = (curRun+1) + " " + stats.cim + " (" + maxCIM + ")";
if (curRun >= maxRuns || stats.cim < maxCIM) {
bmframe.src = "about:blank";
bmframe.style.display = "none";
handleResults(true);
if (window.sessionStorage) delete sessionStorage.JSBNG_harnessState;
return;
}
}
// get out our benchmark and mode
var benchmark = benchmarks[curBenchmark];
var modes = getModes(benchmark);
var mode = modes[curMode];
if (++curMode >= modes.length) {
curMode = 0;
curBenchmark++;
}
if (curBenchmark >= benchmarks.length) {
curBenchmark = 0;
curRun++;
}
// make sure we have the results space
if (!(benchmark in results)) results[benchmark] = {};
if (!(mode in results[benchmark])) results[benchmark][mode] = [];
// Expose time measuring function.
if (window.performance && window.performance.now)
window.currentTimeInMS = function() { return window.performance.now() };
else if (typeof preciseTime !== 'undefined')
window.currentTimeInMS = function() { return preciseTime() * 1000; };
else
window.currentTimeInMS = function() { return Date.now(); };
// set up the receiver
if (/v/.test(mode)) {
// verification mode, we only care if there's an error
window.JSBNG_handleResult = function(res) {
if (res.error) {
if (!("errors" in results)) results.errors = [];
results.errors.push(benchmark + "." + mode + ": " + res.msg);
}
rerun();
};
} else {
window.JSBNG_handleResult = function(res) {
if (!res.error) {
results[benchmark][mode].push(res.time);
}
rerun();
};
}
// then load it
bmframe.src = benchmark + "/" + mode + ".html";
}
// handle all of our results
function handleResults(pr) {
var output = document.getElementById("output");
function print(str) {
output.appendChild(document.createTextNode(str));
output.appendChild(document.createElement("br"));
}
function printarr(arr) {
for (var i = 0; i < arr.length; i++) print(arr[i]);
}
function percent(num) {
return (num*100).toFixed(2) + "%";
}
// clear out the intermediate results
if (pr) output.innerHTML = "";
// totals
var totals = {
mean: 1,
stddev: 1,
sem: 1,
ci: 1,
runs: 0
};
// stuff to print later
var ptotals = [];
var presults = [];
var praw = [];
var spc = "\u00a0\u00a0";
var spc2 = spc + spc;
// calculate all the real results
for (var b = 0; b < benchmarks.length; b++) {
var benchmark = benchmarks[b];
var modes = getModes(benchmark);
if (pr) {
presults.push(spc + benchmark + ":");
praw.push(spc + benchmark + ":");
}
for (var m = 0; m < modes.length; m++) {
var mode = modes[m];
var bmresults = results[benchmark][mode].slice(-keepRuns);
if (bmresults.length == 0) continue;
// get the raw results
var rr = spc2 + mode + ": [";
for (var i = 0; i < bmresults.length; i++) {
if (i != 0) rr += ", ";
rr += bmresults[i];
}
rr += "]";
if (pr) praw.push(rr);
// now get the stats for this run
var bmstats = stats(bmresults);
// mul it to the totals
totals.mean *= bmstats.mean;
totals.stddev *= bmstats.stddev;
totals.sem *= bmstats.sem;
totals.ci *= bmstats.ci;
totals.runs++;
// and output it
if (pr) presults.push(spc2 + mode + ": " +
bmstats.mean.toFixed(2) + "ms ± " + percent(bmstats.cim) +
" (stddev=" + percent(bmstats.sm) + ", stderr=" +
percent(bmstats.semm) + ")");
}
if (pr) {
presults.push("");
praw.push("");
}
}
// now calculate the totals
var power = 1 / totals.runs;
totals.mean = Math.pow(totals.mean, power);
totals.stddev = Math.pow(totals.stddev, power);
totals.sm = totals.stddev / totals.mean;
totals.sem = Math.pow(totals.sem, power);
totals.semm = totals.sem / totals.mean;
totals.ci = Math.pow(totals.ci, power);
totals.cim = totals.ci / totals.mean;
ptotals.push("Final results:");
ptotals.push(spc + totals.mean.toFixed(2) + "ms ± " + percent(totals.cim) + " (lower is better)");
ptotals.push(spc + "Standard deviation = " + percent(totals.sm) + " of mean");
ptotals.push(spc + "Standard error = " + percent(totals.semm) + " of mean");
if (totals.cim >= maxCIM)
ptotals.push(spc + "WARNING: These results are not trustworthy! After " + maxRuns + " runs, 95% confidence interval is still greater than " + percent(maxCIM) + " of the mean!");
else
ptotals.push(spc + curRun + " runs");
ptotals.push("");
// if there are errors, mark those too
if ("errors" in results) {
ptotals.push("ERRORS:");
for (var i = 0; i < results.errors.length; i++) ptotals.push(spc + results.errors[i]);
ptotals.push("");
}
if (pr) {
// and print it all out
printarr(ptotals);
print("Result breakdown:");
printarr(presults);
print("Raw results:");
printarr(praw);
}
return totals;
}
// standard t-distribution for normally distributed samples
var tDistribution = [NaN, NaN, 12.71, 4.30, 3.18, 2.78, 2.57, 2.45, 2.36,
2.31, 2.26, 2.23, 2.20, 2.18, 2.16, 2.14, 2.13, 2.12, 2.11, 2.10, 2.09,
2.09, 2.08, 2.07, 2.07, 2.06, 2.06, 2.06, 2.05, 2.05, 2.05, 2.04, 2.04,
2.04, 2.03, 2.03, 2.03, 2.03, 2.03, 2.02, 2.02, 2.02, 2.02, 2.02, 2.02,
2.02, 2.01, 2.01, 2.01, 2.01, 2.01, 2.01, 2.01, 2.01, 2.01, 2.00, 2.00,
2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00,
2.00, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99,
1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99,
1.99, 1.99, 1.99, 1.99, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.96];
// t distribution
function tDist(n) {
if (n >= tDistribution.length)
return tDistribution[tDistribution.length-1];
return tDistribution[n];
}
// get statistics
function stats(results) {
var ret = {};
function sum(arr) {
return arr.reduce(function(p, c) { return p + c; }, 0);
}
// mean
ret.mean = sum(results) / results.length;
// sample stddev
ret.stddev = Math.sqrt(
sum(
results.map(function(e) { return Math.pow(e - ret.mean, 2); })
) / (results.length - 1)
);
// stddev / mean
ret.sm = ret.stddev / ret.mean;
// sample SEM (stderr)
ret.sem = ret.stddev / Math.sqrt(results.length);
// sample SEM/mean
ret.semm = ret.sem / ret.mean;
// sample 95% confidence interval range
ret.ci = tDist(results.length) * ret.sem;
// sample 95% CI / mean
ret.cim = ret.ci / ret.mean;
return ret;
}
window.onload = onload;
})();