• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML>
2<html>
3  <head>
4    <title>Performance Tests</title>
5    <style>
6      body { font-family: Tahoma, Serif; font-size: 9pt; }
7    </style>
8  </head>
9  <body bgcolor="white">
10    <h1>Performance Tests</h1>
11    <input type="button" value="Run Tests" onClick="run();" id="run"/> Filter: <input type="text" size="50" id="filters"/>
12    <div><span id="statusBox"></span> <progress id="progressBox" value="0" style="display:none"></progress></div>
13
14    <div style="padding-top:10px; padding-bottom:10px">
15    <table id="resultTable" border="1" cellspacing="1" cellpadding="4">
16      <thead>
17        <tr>
18          <td>Name</td>
19          <td>Iterations per Run</td>
20          <td>Avg (ms)</td>
21          <td>Min (ms)</td>
22          <td>Max (ms)</td>
23          <td>StdDev (ms)</td>
24          <td>Runs (ms)</td>
25        </tr>
26      </thead>
27      <!-- result rows here -->
28    </table>
29    </div>
30
31    <hr width="80%">
32
33    Result 1: <input type="text" size="100" id="result1"/>
34    <br/>Result 2: <input type="text" size="100" id="result2"/>
35    <br/><input type="button" value="Compare" onClick="compare();" id="compare"/>
36
37    <div style="padding-top:10px; padding-bottom:10px">
38    <table id="compareTable" border="1" cellspacing="1" cellpadding="4">
39      <thead>
40        <tr>
41          <td>Name</td>
42          <td>Result 1 Avg (ms)</td>
43          <td>Result 2 Avg (ms)</td>
44          <td>% Diff</td>
45        </tr>
46      </thead>
47      <!-- result rows here -->
48    </table>
49    </div>
50
51<script type="text/javascript">
52function run() {
53  var runElement = document.getElementById("run");
54  var filtersElement = document.getElementById("filters");
55  var compareElement = document.getElementById("compare");
56  var result1Element = document.getElementById("result1");
57  var result2Element = document.getElementById("result2");
58
59  // Number of runs for each test.
60  var testRuns = 10;
61
62  // Delay between test runs.
63  var runDelay = 0;
64
65  // Retrieve the list of all tests.
66  var allTests = window.GetPerfTests();
67
68  // Populated with the list of tests that will be run.
69  var tests = [];
70  var currentTest = 0;
71
72  var testList = filtersElement.value.trim();
73  if (testList.length > 0) {
74    // Include or exclude specific tests.
75    var included = [];
76    var excluded = [];
77
78    var testNames = testList.split(",");
79
80    // Identify included and excluded tests.
81    for (i = 0; i < testNames.length; ++i) {
82      var testName = testNames[i].trim();
83      if (testName[0] == '-') {
84        // Exclude the test.
85        excluded.push(testName.substr(1));
86      } else {
87        // Include the test.
88        included.push(testName);
89      }
90    }
91
92    if (included.length > 0) {
93      // Only use the included tests.
94      for (i = 0; i < allTests.length; ++i) {
95        var test = allTests[i];
96        var testName = test[0];
97        if (included.indexOf(testName) >= 0)
98          tests.push(test);
99      }
100    } else if (excluded.length > 0) {
101      // Use all tests except the excluded tests.
102      for (i = 0; i < allTests.length; ++i) {
103        var test = allTests[i];
104        var testName = test[0];
105        if (excluded.indexOf(testName) < 0)
106          tests.push(test);
107      }
108    }
109  } else {
110    // Run all tests.
111    tests = allTests;
112  }
113
114  function updateStatusComplete() {
115    var statusBox = document.getElementById("statusBox");
116    statusBox.innerText = 'All tests completed.';
117
118    runElement.disabled = false;
119    filtersElement.disabled = false;
120    result1Element.disabled = false;
121    result2Element.disabled = false;
122    compareElement.disabled = false;
123  }
124
125  function updateStatus(test) {
126    var statusBox = document.getElementById("statusBox");
127    var progressBox = document.getElementById("progressBox");
128
129    if (test.run >= test.totalRuns) {
130      statusBox.innerText = test.name + " completed.";
131      progressBox.style.display = 'none';
132    } else {
133      statusBox.innerText = test.name + " (" + test.run + "/" + test.totalRuns + ")";
134      progressBox.value = (test.run / test.totalRuns);
135      progressBox.style.display = 'inline';
136    }
137  }
138
139  function appendResult(test) {
140    var e = document.getElementById("resultTable");
141
142    // Calculate the average.
143    var avg = test.total / test.totalRuns;
144
145    // Calculate the standard deviation.
146    var sqsum = 0;
147    for (i = 0; i < test.results.length; ++i) {
148      var diff = test.results[i] - avg;
149      sqsum += diff * diff;
150    }
151    var stddev = Math.round(Math.sqrt(sqsum / test.totalRuns) * 100.0) / 100.0;
152
153    e.insertAdjacentHTML("beforeEnd", [
154        "<tr>",
155        "<td>", test.name, "</td>",
156        "<td>", test.iterations, "</td>",
157        "<td>", avg, "</td>",
158        "<td>", test.min, "</td>",
159        "<td>", test.max, "</td>",
160        "<td>", stddev, "</td>",
161        "<td>", test.results.join(", "), "</td>",
162        "<tr>"
163        ].join(""));
164
165    if (result1Element.value.length > 0)
166      result1Element.value += ",";
167    result1Element.value += test.name + "=" + avg;
168  }
169
170  // Execute the test function.
171  function execTestFunc(name) {
172    return window.RunPerfTest(name);
173  }
174
175  // Schedule the next test.
176  function nextTest(test) {
177    appendResult(test);
178    currentTest++;
179    runTest();
180  }
181
182  // Schedule the next step for the current test.
183  function nextTestStep(test) {
184    setTimeout(function () { execTest(test); }, runDelay);
185  }
186
187  // Perform the next step for the current test.
188  function execTest(test) {
189    updateStatus(test);
190
191    if (!test.warmedUp) {
192      execTestFunc(test.name);
193      test.warmedUp = true;
194      return nextTestStep(test);
195    }
196
197    if (test.run >= test.totalRuns)
198      return nextTest(test);
199
200    var elapsed = execTestFunc(test.name);
201    test.results.push(elapsed);
202
203    test.total += elapsed;
204    if (!test.min) test.min = elapsed;
205    else if (test.min > elapsed) test.min = elapsed;
206    if (!test.max) test.max = elapsed;
207    else if (test.max < elapsed) test.max = elapsed;
208
209    test.run++;
210
211    return nextTestStep(test);
212  }
213
214  function runTest() {
215    if (currentTest == tests.length) {
216      updateStatusComplete();
217      return;
218    }
219
220    var test = {
221        name: tests[currentTest][0],
222        iterations: tests[currentTest][1],
223        warmedUp: false,
224        total: 0,
225        totalRuns: testRuns,
226        run: 0,
227        results: []
228    };
229    setTimeout(function () { execTest(test); }, runDelay);
230  }
231
232  // Schedule the first test.
233  if (tests.length > 0) {
234    runElement.disabled = true;
235    filtersElement.disabled = true;
236    result1Element.value = "";
237    result1Element.disabled = true;
238    result2Element.disabled = true;
239    compareElement.disabled = true;
240
241    runTest();
242  }
243}
244
245function compare() {
246  var result1 = document.getElementById("result1").value.trim();
247  var result2 = document.getElementById("result2").value.trim();
248
249  if (result1.length == 0 || result2.length == 0)
250    return;
251
252  var r1values = result1.split(",");
253  var r2values = result2.split(",");
254  for (i = 0; i < r1values.length; ++i) {
255    var r1parts = r1values[i].split("=");
256    var r1name = r1parts[0].trim();
257    var r1val = r1parts[1].trim();
258
259    for (x = 0; x < r2values.length; ++x) {
260      var r2parts = r2values[x].split("=");
261      var r2name = r2parts[0].trim();
262      var r2val = r2parts[1].trim();
263
264      if (r2name == r1name) {
265        appendResult(r1name, r1val, r2val);
266
267        // Remove the matching index.
268        r2values.splice(x, 1);
269        break;
270      }
271    }
272  }
273
274  function appendResult(name, r1val, r2val) {
275    var e = document.getElementById("compareTable");
276
277    // Calculate the percent difference.
278    var diff = Math.round(((r2val - r1val) / r1val) * 10000.0) / 100.0;
279
280    e.insertAdjacentHTML("beforeEnd", [
281        "<tr>",
282        "<td>", name, "</td>",
283        "<td>", r1val, "</td>",
284        "<td>", r2val, "</td>",
285        "<td>", diff, "</td>",
286        "<tr>"
287        ].join(""));
288  }
289}
290</script>
291
292  </body>
293</html>
294