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
|
<!DOCTYPE html>
<html>
<head>
<title>Speedometer 2.1 Interactive Runner</title>
<script src="resources/benchmark-runner.js" defer></script>
<script src="resources/tests.js" defer></script>
<style>
iframe { border: 1px solid black; }
ol { list-style: none; margin: 0; padding: 0; }
ol ol { margin-left: 2em; list-position: outside; }
.running { text-decoration: underline; }
.ran { color: grey; }
nav { position: absolute; right: 10px; height: 600px; }
nav > ol { height: 100%; overflow-y: scroll; }
</style>
</head>
<body>
<script>
function formatTestName(suiteName, testName) {
return suiteName + (testName ? '/' + testName : '');
}
function createUIForSuites(suites, onstep, onrun) {
var control = document.createElement('nav');
var ol = document.createElement('ol');
var checkboxes = [];
for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) {
var suite = suites[suiteIndex];
var li = document.createElement('li');
var checkbox = document.createElement('input');
checkbox.id = suite.name;
checkbox.type = 'checkbox';
checkbox.checked = !suite.disabled;
checkbox.onchange = (function (suite, checkbox) { return function () { suite.disabled = !checkbox.checked; } })(suite, checkbox);
checkbox.onchange();
checkboxes.push(checkbox);
li.appendChild(checkbox);
var label = document.createElement('label');
label.appendChild(document.createTextNode(formatTestName(suite.name)));
li.appendChild(label);
label.htmlFor = checkbox.id;
var testList = document.createElement('ol');
for (var testIndex = 0; testIndex < suite.tests.length; testIndex++) {
var testItem = document.createElement('li');
var test = suite.tests[testIndex];
var anchor = document.createElement('a');
anchor.id = suite.name + '-' + test.name;
test.anchor = anchor;
anchor.appendChild(document.createTextNode(formatTestName(suite.name, test.name)));
testItem.appendChild(anchor);
testList.appendChild(testItem);
}
li.appendChild(testList);
ol.appendChild(li);
}
control.appendChild(ol);
var button = document.createElement('button');
button.textContent = 'Step';
button.onclick = onstep;
control.appendChild(button);
var button = document.createElement('button');
button.textContent = 'Run';
button.id = 'runSuites';
button.onclick = onrun;
control.appendChild(button);
var button = document.createElement('button');
button.textContent = 'Select all';
button.onclick = function () {
for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) {
suites[suiteIndex].disabled = false;
checkboxes[suiteIndex].checked = true;
}
};
control.appendChild(button);
var button = document.createElement('button');
button.textContent = 'Unselect all';
button.onclick = function () {
for (var suiteIndex = 0; suiteIndex < suites.length; suiteIndex++) {
suites[suiteIndex].disabled = true;
checkboxes[suiteIndex].checked = false;
}
};
control.appendChild(button);
return control;
}
var parseQueryString = (function (pairList) {
var pairs = {};
for (var i = 0; i < pairList.length; ++i) {
var keyValue = pairList[i].split('=', 2);
if (keyValue.length == 1)
pairs[keyValue[0]] = '';
else
pairs[keyValue[0]] = decodeURIComponent(keyValue[1].replace(/\+/g, ' '));
}
return pairs;
})(window.location.search.substr(1).split('&'));
function disableAllSuitesExcept(suiteName) {
Suites.forEach(function(element) {
if (element.name !== suiteName)
element.disabled = true;
});
}
function startTest() {
var queryParam = parseQueryString['suite'];
if (queryParam !== undefined)
disableAllSuitesExcept(queryParam);
var runner = new BenchmarkRunner(Suites, {
willRunTest: function (suite, test) {
test.anchor.classList.add('running');
},
didRunTest: function (suite, test) {
var classList = test.anchor.classList;
classList.remove('running');
classList.add('ran');
},
didRunSuites: function (measuredValues) {
var results = '';
for (var suiteName in measuredValues.tests) {
var suiteResults = measuredValues.tests[suiteName];
for (var testName in suiteResults.tests) {
var testResults = suiteResults.tests[testName];
for (var subtestName in testResults.tests) {
results += suiteName + ' : ' + testName + ' : ' + subtestName
+ ': ' + testResults.tests[subtestName] + ' ms\n';
}
}
results += suiteName + ' : ' + suiteResults.total + ' ms\n';
}
results += 'Arithmetic Mean : ' + measuredValues.mean + ' ms\n';
results += 'Geometric Mean : ' + measuredValues.geomean + ' ms\n';
results += 'Total : ' + measuredValues.total + ' ms\n';
results += 'Score : ' + measuredValues.score + ' rpm\n';
if (!results)
return;
var pre = document.createElement('pre');
document.body.appendChild(pre);
pre.textContent = results;
}
});
var currentState = null;
// Don't call step while step is already executing.
document.body.appendChild(createUIForSuites(Suites,
function () { runner.step(currentState).then(function (state) { currentState = state; }); },
function () { runner.runAllSteps(currentState); currentState = null; }));
if (parseQueryString['startAutomatically'] !== undefined)
document.getElementById('runSuites').click();
}
window.addEventListener('load', startTest);
</script>
</body>
</html>
|