antti@apple.com | 18af471 | 2017-11-30 12:30:25 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Speedometer 2.0 Interactive Runner</title> |
| 5 | <script src="../Speedometer/resources/benchmark-runner.js" defer></script> |
antti@apple.com | 8db8781 | 2017-12-04 15:32:41 +0000 | [diff] [blame] | 6 | <script src="resources/style-bench.js" defer></script> |
| 7 | <script src="resources/tests.js" defer></script> |
antti@apple.com | 18af471 | 2017-11-30 12:30:25 +0000 | [diff] [blame] | 8 | <style> |
| 9 | iframe { border: 1px solid black; } |
| 10 | ol { list-style: none; margin: 0; padding: 0; } |
| 11 | ol ol { margin-left: 2em; list-position: outside; } |
| 12 | .running { text-decoration: underline; } |
| 13 | .ran { color: grey; } |
| 14 | nav { position: absolute; right: 10px; height: 600px; } |
| 15 | nav > ol { height: 100%; overflow-y: scroll; } |
| 16 | </style> |
| 17 | </head> |
| 18 | <body> |
| 19 | <script> |
| 20 | |
| 21 | function formatTestName(suiteName, testName) { |
| 22 | return suiteName + (testName ? '/' + testName : ''); |
| 23 | } |
| 24 | |
| 25 | function createUIForSuites(suites, onstep, onrun) { |
| 26 | var control = document.createElement('nav'); |
| 27 | var ol = document.createElement('ol'); |
| 28 | var checkboxes = []; |
| 29 | for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) { |
| 30 | var suite = suites[suiteIndex]; |
| 31 | var li = document.createElement('li'); |
| 32 | var checkbox = document.createElement('input'); |
| 33 | checkbox.id = suite.name; |
| 34 | checkbox.type = 'checkbox'; |
| 35 | checkbox.checked = !suite.disabled; |
| 36 | checkbox.onchange = (function (suite, checkbox) { return function () { suite.disabled = !checkbox.checked; } })(suite, checkbox); |
| 37 | checkbox.onchange(); |
| 38 | checkboxes.push(checkbox); |
| 39 | |
| 40 | li.appendChild(checkbox); |
| 41 | var label = document.createElement('label'); |
| 42 | label.appendChild(document.createTextNode(formatTestName(suite.name))); |
| 43 | li.appendChild(label); |
| 44 | label.htmlFor = checkbox.id; |
| 45 | |
| 46 | var testList = document.createElement('ol'); |
| 47 | for (var testIndex = 0; testIndex < suite.tests.length; testIndex++) { |
| 48 | var testItem = document.createElement('li'); |
| 49 | var test = suite.tests[testIndex]; |
| 50 | var anchor = document.createElement('a'); |
| 51 | anchor.id = suite.name + '-' + test.name; |
| 52 | test.anchor = anchor; |
| 53 | anchor.appendChild(document.createTextNode(formatTestName(suite.name, test.name))); |
| 54 | testItem.appendChild(anchor); |
| 55 | testList.appendChild(testItem); |
| 56 | } |
| 57 | li.appendChild(testList); |
| 58 | |
| 59 | ol.appendChild(li); |
| 60 | } |
| 61 | |
| 62 | control.appendChild(ol); |
| 63 | |
| 64 | var button = document.createElement('button'); |
| 65 | button.textContent = 'Step'; |
| 66 | button.onclick = onstep; |
| 67 | control.appendChild(button); |
| 68 | |
| 69 | var button = document.createElement('button'); |
| 70 | button.textContent = 'Run'; |
| 71 | button.id = 'runSuites'; |
| 72 | button.onclick = onrun; |
| 73 | control.appendChild(button); |
| 74 | |
| 75 | var button = document.createElement('button'); |
| 76 | button.textContent = 'Select all'; |
| 77 | button.onclick = function () { |
| 78 | for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) { |
| 79 | suites[suiteIndex].disabled = false; |
| 80 | checkboxes[suiteIndex].checked = true; |
| 81 | } |
| 82 | }; |
| 83 | control.appendChild(button); |
| 84 | |
| 85 | var button = document.createElement('button'); |
| 86 | button.textContent = 'Unselect all'; |
| 87 | button.onclick = function () { |
| 88 | for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) { |
| 89 | suites[suiteIndex].disabled = true; |
| 90 | checkboxes[suiteIndex].checked = false; |
| 91 | } |
| 92 | |
| 93 | }; |
| 94 | control.appendChild(button); |
| 95 | |
| 96 | return control; |
| 97 | } |
| 98 | |
| 99 | var parseQueryString = (function (pairList) { |
| 100 | var pairs = {}; |
| 101 | for (var i = 0; i < pairList.length; ++i) { |
| 102 | var keyValue = pairList[i].split('=', 2); |
| 103 | if (keyValue.length == 1) |
| 104 | pairs[keyValue[0]] = ''; |
| 105 | else |
| 106 | pairs[keyValue[0]] = decodeURIComponent(keyValue[1].replace(/\+/g, ' ')); |
| 107 | } |
| 108 | return pairs; |
| 109 | })(window.location.search.substr(1).split('&')); |
| 110 | |
| 111 | function disableAllSuitesExcept(suiteName) { |
| 112 | Suites.forEach(function(element) { |
| 113 | if (element.name !== suiteName) |
| 114 | element.disabled = true; |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | function startTest() { |
| 119 | var queryParam = parseQueryString['suite']; |
| 120 | if (queryParam !== undefined) |
| 121 | disableAllSuitesExcept(queryParam); |
| 122 | |
| 123 | var runner = new BenchmarkRunner(Suites, { |
| 124 | willRunTest: function (suite, test) { |
| 125 | test.anchor.classList.add('running'); |
| 126 | }, |
| 127 | didRunTest: function (suite, test) { |
| 128 | var classList = test.anchor.classList; |
| 129 | classList.remove('running'); |
| 130 | classList.add('ran'); |
| 131 | }, |
| 132 | didRunSuites: function (measuredValues) { |
| 133 | var results = ''; |
| 134 | for (var suiteName in measuredValues.tests) { |
| 135 | var suiteResults = measuredValues.tests[suiteName]; |
| 136 | for (var testName in suiteResults.tests) { |
| 137 | var testResults = suiteResults.tests[testName]; |
| 138 | for (var subtestName in testResults.tests) { |
| 139 | results += suiteName + ' : ' + testName + ' : ' + subtestName |
| 140 | + ': ' + testResults.tests[subtestName] + ' ms\n'; |
| 141 | } |
| 142 | } |
| 143 | results += suiteName + ' : ' + suiteResults.total + ' ms\n'; |
| 144 | } |
| 145 | results += 'Arithmetic Mean : ' + measuredValues.mean + ' ms\n'; |
| 146 | results += 'Geometric Mean : ' + measuredValues.geomean + ' ms\n'; |
| 147 | results += 'Total : ' + measuredValues.total + ' ms\n'; |
| 148 | results += 'Score : ' + measuredValues.score + ' rpm\n'; |
| 149 | |
| 150 | if (!results) |
| 151 | return; |
| 152 | |
| 153 | var pre = document.createElement('pre'); |
| 154 | document.body.appendChild(pre); |
| 155 | pre.textContent = results; |
| 156 | } |
| 157 | }); |
| 158 | |
| 159 | var currentState = null; |
| 160 | |
| 161 | // Don't call step while step is already executing. |
| 162 | document.body.appendChild(createUIForSuites(Suites, |
| 163 | function () { runner.step(currentState).then(function (state) { currentState = state; }); }, |
| 164 | function () { runner.runAllSteps(currentState); currentState = null; })); |
| 165 | |
| 166 | if (parseQueryString['startAutomatically'] !== undefined) |
| 167 | document.getElementById('runSuites').click(); |
| 168 | } |
| 169 | |
| 170 | window.addEventListener('load', startTest); |
| 171 | |
| 172 | </script> |
| 173 | </body> |
| 174 | </html> |