summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/examples/extensions/benchmark/options.html
blob: 33440da360d82307b80f75bfeed71dceaf83c4b8 (plain)
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<head>
  <title>Page Benchmark Options</title>
  <script src="jst/util.js" type="text/javascript"></script>
  <script src="jst/jsevalcontext.js" type="text/javascript"></script>
  <script src="jst/jstemplate.js" type="text/javascript"></script>
  <script src="jst/jstemplate_example.js" type="text/javascript"></script>

<style>
body {
  font-size: 84%;
  font-family: Helvetica, Arial, sans-serif;
  padding: 0.75em;
  margin: 0;
  min-width: 45em;
}

h1 {
  font-size: 110%;
  font-weight: bold;
  color: #4a8ee6;
  letter-spacing: -1px;
  padding: 0;
  margin: 0;
}

div#header {
  padding: 0.75em 1em;
  padding-top: 0.6em;
  padding-left: 10;
  margin-bottom: 0.75em;
  position: relative;
  overflow: hidden;
  background: #5296de;
  -webkit-background-size: 100%;
  border: 1px solid #3a75bd;
  -webkit-border-radius: 6px;
  color: white;
  text-shadow: 0 0 2px black;
}
div#header h1 {
  padding-left: 37px;
  margin: 0;
  display: inline;
  color: white;
}
div#header p {
  font-size: 84%;
  font-style: italic;
  padding: 0;
  margin: 0;
  color: white;
  padding-left: 0.4em;
  display: inline;
}

table.list {
  font-size: 84%;
  table-layout: fixed;
}

table.list:not([class*='filtered']) tr:nth-child(odd) td:not([class*='filtered']) {
  background: #eff3ff;
}

table.list th {
  padding: 0 0.5em;
  vertical-align: bottom;
  font-weight: bold;
  color: #315d94;
  color: black;
  text-align: center;
}

.avg {
  font-weight: bold;
  text-align: center;
}

.data {
  text-align: left;
  white-space: nowrap;
}

.bggraph {
  background-color: #faa;
  white-space: nowrap;
}
</style>

<script>

var max_sample = 0;

Array.max = function(array) {
  return Math.max.apply( Math, array );
}

Array.min = function(array) {
  return Math.min.apply( Math, array );
};

// Compute the average of an array, removing the min/max.
Array.avg = function(array) {
  var count = array.length;
  var sum = 0;
  var min = array[0];
  var max = array[0];
  for (var i = 0; i < count; i++) {
    sum += array[i];
    if (array[i] < min) {
      min = array[i];
    }
    if (array[i] > max) {
      max = array[i];
    }
  }
  if (count >= 3) {
    sum = sum - min - max;
    count -= 2;
  }
  return sum / count;
}

// Compute the standard deviation of an array
Array.stddev = function(array) {
  var count = array.length;
  var mean = Array.avg(array);
  var variance = 0;
  for (var i = 0; i < count; i++) {
    var deviation = mean - array[i];
    variance = variance + deviation * deviation;
  }
  variance = variance / count;
  return Math.sqrt(variance);
}

// Object to summarize everything
var totals = {};

// Compute the results for a data set.
function computeDisplayResults(data) {
  var count = data.data.length;
  for (var i = 0; i < count; i++) {
    var obj = data.data[i];
    var resultList = obj.totalResults;
    obj.mean = Array.avg(resultList);
    obj.stddev = Array.stddev(resultList);
    obj.stderr = obj.stddev / Math.sqrt(obj.iterations);
    var ci = 1.96 * obj.stderr;
    obj.cihigh = obj.mean + ci;
    obj.cilow = obj.mean - ci;
    obj.min = Array.min(resultList);
    obj.max = Array.max(resultList);
    obj.readbps = obj.bytesRead * 8 / obj.totalTime;
    obj.writebps = obj.bytesWritten * 8 / obj.totalTime;
    obj.readKB = obj.bytesRead / 1024;
    obj.writeKB = obj.bytesWritten / 1024;
    obj.paintMean = Array.avg(obj.paintResults);
    obj.startLoadMean = Array.avg(obj.startLoadResults);
    obj.commitLoadMean = Array.avg(obj.commitLoadResults);
    obj.docLoadMean = Array.avg(obj.docLoadResults);

    obj.displayRequests = obj.requests;
    obj.displayConnects = obj.connects
    obj.displaySpdySessions = obj.spdySessions;
  }
  return count;
}

// Subtract the results from two data sets.
// This function could be smarter about what it subtracts,
// for now it just subtracts everything.
// Returns true if it was able to compare the two data sets.
function subtractData(data, baseline) {
  var count = data.data.length;
  if (baseline.data.length != count) {
    return false;
  }
  for (var i = 0; i < count; i++) {
    var obj = data.data[i];
    var obj2 = baseline.data[i];

    // The data sets are different.
    if (obj.url != obj2.url ||
        obj.iterations != obj2.iterations) {
      return false;
    }

    obj.mean -= obj2.mean;
    obj.stddev -= obj2.stddev;
    obj.min -= obj2.min;
    obj.max -= obj2.max;
    obj.readbps -= obj2.readbps;
    obj.writebps -= obj2.writebps;
    obj.readKB -= obj2.readKB;
    obj.writeKB -= obj2.writeKB;
    obj.paintMean -= obj2.paintMean;
    obj.startLoadMean -= obj2.startLoadMean;
    obj.commitLoadMean -= obj2.commitLoadMean;
    obj.docLoadMean -= obj2.docLoadMean;

    obj.displayRequests -= obj2.displayRequests;
    obj.displayConnects -= obj2.displayConnects;
    obj.displaySpdySessions -= obj2.displaySpdySessions;
  }
  return true;
}

// Compute totals based on a data set.
function computeTotals(data) {
  var count = data.data.length;
  for (var i = 0; i < count; i++) {
    var obj = data.data[i];
    totals.mean += obj.mean;
    totals.paintMean += obj.paintMean;
    totals.startLoadMean += obj.startLoadMean;
    totals.commitLoadMean += obj.commitLoadMean;
    totals.docLoadMean += obj.docLoadMean;
  }
}

// Compute results for the data with an optional baseline.
// If |baseline| is undefined, will compute the results of this
// run.  Otherwise, computes the diff between this data and the baseline.
function computeResults(data, baseline) {
  totals = {};
  totals.mean = 0;
  totals.paintMean = 0;
  totals.startLoadMean = 0;
  totals.commitLoadMean = 0;
  totals.docLoadMean = 0;

  var count = computeDisplayResults(data);

  if (baseline) {
    computeDisplayResults(baseline);
    if (!subtractData(data, baseline)) {
      alert("These data sets are different");
      document.getElementById("baseline").value = "";
      return;
    }
  }

  computeTotals(data);
  totals.url = "(" + count + " urls)";
  if (count > 0) {
    totals.mean /= count;
    totals.paintMean /= count;
    totals.startLoadMean /= count;
    totals.commitLoadMean /= count;
    totals.docLoadMean /= count;
  }

  // Find the biggest average for our bar graph.
  max_sample = 0;
  for (var i = 0; i < data.data.length; i++) {
    if (data.data[i].max > max_sample) {
      max_sample = data.data[i].mean;
    }
  }
}

function jsinit() {
  var extension = chrome.extension.getBackgroundPage();

  // Run the template to show results
  var data = extension.results;

  // Get the baseline results
  var elt = document.getElementById("baseline");
  var baseline_json = document.getElementById("baseline").value;
  var baseline;
  if (baseline_json) {
    try {
      baseline = JSON.parse(baseline_json);
    } catch (e) {
      alert("JSON parse error: " + e);
    }
  }

  // Compute
  computeResults(data, baseline);

  var context = new JsEvalContext(data);
  context.setVariable('$width', 0);
  context.setVariable('$samples', 0);
  var template = document.getElementById("t");
  jstProcess(context, template);

  // Set the options
  document.getElementById("iterations").value = extension.iterations;
  document.getElementById("clearconns").checked = extension.clearConnections;
  document.getElementById("clearcache").checked = extension.clearCache;
  document.getElementById("enablespdy").checked = extension.enableSpdy;
  setUrl(extension.testUrl);

  if (!baseline) {
    var json_data = JSON.stringify(data);
    document.getElementById("json").value = json_data;
  }
}

function getWidth(mean, obj) {
  var kMinWidth = 200;
  var max_width = obj.offsetWidth;
  if (max_width < kMinWidth) {
    max_width = kMinWidth;
  }
  return Math.floor(max_width * (mean / max_sample));
}

// Apply configuration back to our extension
function config() {
  var extension = chrome.extension.getBackgroundPage();
  var iterations = parseInt(document.getElementById("iterations").value);
  var clearConnections = document.getElementById("clearconns").checked;
  var clearCache = document.getElementById("clearcache").checked;
  var enableSpdy = document.getElementById("enablespdy").checked;
  if (iterations > 0) {
    extension.iterations = iterations;
    extension.clearConnections = clearConnections;
    extension.clearCache = clearCache;
    extension.enableSpdy = enableSpdy;
  }
}

// Set the url in the benchmark url box.
function setUrl(url) {
  document.getElementById("testurl").value = url;
}

// Start the benchmark.
function run() {
  if (!chrome.benchmarking) {
    alert("Warning:  Looks like you forgot to run chrome with " +
          " --enable-benchmarking set.");
    return;
  }
  var extension = chrome.extension.getBackgroundPage();
  var testUrl = document.getElementById("testurl").value;
  extension.testUrl = testUrl;
  extension.run();
}

// Clear the results
function clearResults() {
  var extension = chrome.extension.getBackgroundPage();
  extension.results = {};
  extension.results.data = new Array();
  document.getElementById("json").value = "";
  document.getElementById("baseline").value = "";
  jsinit();
}

// Toggle display of an element
function toggle(id) {
  var elt = document.getElementById(id);
  if (elt.style.display == "none") {
    elt.style.display = "block";
  } else {
    elt.style.display = "none";
  }
}
</script>

</head>

<body onload="jsinit()">

<h1><div id="header">Page Benchmark Results</div></h1>

<h1>Configuration</h1>

<span>Iterations</span>
<input id="iterations" type=text style="text-align:right">
<input type="button" value="Clear Results" onclick="clearResults();">
<nb/>
Clear Connections?<input id="clearconns" type="checkbox">
Clear Cache?<input id="clearcache" type="checkbox">
Enable Spdy?<input id="enablespdy" type="checkbox">
<form onsubmit="config(); run()">
  URL to load <input type="text" id="testurl" size=100>
  <input type="submit" value="Run"><P>
</form>
<p>

<h1>Results</h1>

<table id="t" class="list" width="100%">
  <tr>
  <th width=200px>url</th>
  <th width=50>iterations</th>
  <th width=50>via spdy</th>
  <th width=50>start load mean</th>
  <th width=50>commit load mean</th>
  <th width=50>doc load mean</th>
  <th width=50>paint mean</th>
  <th width=50>total mean</th>
  <th width=50>stddev</th>
  <th width=50>stderr</th>
  <th width=50>95% CI-low</th>
  <th width=50>95% CI-high</th>
  <th width=50>min</th>
  <th width=50>max</th>
  <th width=50># Requests</th>
  <th width=50># Connects</th>
  <th width=50># SPDY Sessions</th>
  <th width=50>Read KB</th>
  <th width=50>Write KB</th>
  <th width=50>Read KBps</th>
  <th width=50>Write KBps</th>
  <th samples></th>
  </tr>

  <tr id="t.total" jsselect="totals">
  <td class="url">TOTALS <span jscontent="url"></span></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg"><span jseval="val = startLoadMean.toFixed(1)" jscontent="val"></span></td>
  <td class="avg"><span jseval="val = commitLoadMean.toFixed(1)" jscontent="val"></span></td>
  <td class="avg"><span jseval="val = docLoadMean.toFixed(1)" jscontent="val"></span></td>
  <td class="avg"><span jseval="val = paintMean.toFixed(1)" jscontent="val"></span></td>
  <td class="avg"><span jseval="val = mean.toFixed(1)" jscontent="val"></span></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="avg" jseval="1"></td>
  <td class="data"></td>
  </tr>

  <tr jsselect="data">
  <td class="url" jseval="$width = getWidth($this.mean, this); url.length > 40 ? $suburl = url.substring(0,27) + '...' + url.substring(url.length-10, url.length) : $suburl=url"><div jsvalues=".style.width:$width" class="bggraph"><a jsvalues="href:$this.url" jscontent="$suburl"></a></div></td>
  <td class="avg" jseval="val = iterations" jscontent="val"></td>
  <td class="avg" jseval="val = viaSpdy" jscontent="val"></td>
  <td class="avg" jseval="val = startLoadMean.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = commitLoadMean.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = docLoadMean.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = paintMean.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = mean.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = stddev.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = stderr.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = cilow.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = cihigh.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = min.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = max.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = displayRequests" jscontent="val"></td>
  <td class="avg" jseval="val = displayConnects" jscontent="val"></td>
  <td class="avg" jseval="val = displaySpdySessions" jscontent="val"></td>
  <td class="avg" jseval="val = readKB.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = writeKB.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = readbps.toFixed(1)" jscontent="val"></td>
  <td class="avg" jseval="val = writebps.toFixed(1)" jscontent="val"></td>
  <td class="data"><span jsselect="totalResults"><span jscontent="$this"></span>,</span> </td>
  </tr>
  <tr jsdisplay="data.length == 0">
  <td colspan=11>No tests have been run yet.</td>
  </tr>
</table>

<hr>
<span onclick="toggle('json')">JSON data</span><br>
<textarea style="display: none" type=text id=json rows=10 cols=50></textarea><p>

<span onclick="toggle('baseline')">COMPARE to</span><br>
<textarea style="display: none" type=text id=baseline rows=10 cols=50
onchange="jsinit()"></textarea><p>
</body>