-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
180 lines (169 loc) · 5.24 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src="config.js"></script>
<script src="tests.js"></script>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.2.0/pure-min.css">
<style type="text/css">
body { padding: 100px; }
iframe { border: 0; height: 0; width: 0; }
#controls { margin-bottom: 20px; }
#add-framework-form { margin-top: 20px; }
.pure-button-secondary {
color: white;
border-radius: 4px;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.pure-button-secondary {
background: rgb(66, 184, 221); /* this is a light blue */
}
.error { color: rgb(202, 60, 60); }
#testSrcLink, .num-runs, .approx { color: #999; font-size: 12px; }
</style>
</head>
<body>
<div id="controls">
<button id="start-button" class="pure-button pure-button-secondary">Start Tests</button>
</div>
<table class="pure-table pure-table-bordered">
<thead>
<tr id="header-row">
<th>Test <a href="tests.js" id="testSrcLink">src</a></th>
</tr>
</thead>
<tbody id="result-table">
</tbody>
</table>
<form action="#" id="add-framework-form">
<input type="text" id="add-framework-value" placeholder="http://path/to/react.js" />
<button class="pure-button">Add Framework</button>
</form>
<script type="text/javascript">
function getParametersByName(name) {
var match;
var matches = [];
var re = RegExp('[?&]' + name + '=([^&]*)', 'g');
while ((match = re.exec(window.location.search)) !== null) {
matches.push(decodeURIComponent(match[1].replace(/\+/g, ' ')));
}
return matches;
}
var preloadSrc = getParametersByName('frameworkSrc');
if (preloadSrc.length > 0) {
FRAMEWORK_SOURCES = FRAMEWORK_SOURCES.concat(preloadSrc);
}
var FrameworkTests = {};
var resultTable = document.getElementById('result-table');
var headerRow = document.getElementById('header-row');
function initFramework(src) {
var iframe = document.createElement('iframe');
iframe.width = 0;
iframe.height = 0;
iframe.src = 'iframe.html?src=' + src;
document.body.appendChild(iframe);
iframe.onload = function() {
iframe.contentWindow.postMessage('onload', iframe.contentWindow.location.origin);
};
FrameworkTests[src] = {};
window.addEventListener('message', function(msg) {
if (msg.data === 'ready') {
FrameworkTests[src] = iframe.contentWindow.Tests;
}
}, false);
var headerCell = document.createElement('th');
headerCell.innerHTML = src;
headerRow.appendChild(headerCell);
}
FRAMEWORK_SOURCES.forEach(function(framework_source) {
initFramework(framework_source);
});
function formatNumber(number) {
if (number >= 100) {
var numberStr = Math.round(number).toString();
// Put commas every 3 digits
while (/(\d+)(\d{3})/.test(numberStr)){
numberStr = numberStr.replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return numberStr;
}
// If it's a small number, then have 2 digits of precision
return number.toFixed(2);
}
var TestNames = [];
for (var testName in TESTS) {
TestNames.push(testName);
}
var TestObjs;
function initTests() {
resultTable.innerHTML = '';
TestObjs = TestNames.map(function(testName) {
var testObj = {
frameworks: []
};
var row = document.createElement('tr');
resultTable.appendChild(row);
row.innerHTML = '<td>' + testName + '</td>';
for (var framework in FrameworkTests) {
var cell = document.createElement('td');
testObj.frameworks.push({
run: function(framework, cell, callback) {
FrameworkTests[framework][testName](function(result) {
cell.innerHTML = formatNumber(result.hz) + ' <small>ops/s</small> ' +
'<span title="' + formatNumber(result.hz * (1 - result.rme / 100)) + ' - ' + formatNumber(result.hz * (1 + result.rme / 100)) + '" class="approx">\xb1' + formatNumber(result.rme) + '%</span> ' +
'<span class="num-runs">(' + result.runs + ' runs)</span>';
callback();
});
}.bind(null, framework, cell),
clear: function(cell) {
cell.innerHTML = '';
}.bind(null, cell)
});
row.appendChild(cell);
}
return testObj;
});
}
initTests();
var runnerInterval;
var startButton = document.getElementById('start-button');
startButton.addEventListener('click', function() {
startButton.innerHTML = 'Tests running...';
if (startButton.classList) {
startButton.classList.add('pure-button-disabled');
}
if (runnerInterval) {
clearInterval(runnerInterval);
runnerInterval = null;
}
var testRunners = [];
TestObjs.forEach(function(testObj) {
testObj.frameworks.forEach(function(framework) {
framework.clear();
testRunners.push(framework.run);
});
});
var runTest = function() {
var runner = testRunners.shift();
if (runner) {
runner(function() {
// minor breathing room between tests
setTimeout(runTest, 10);
});
} else {
startButton.innerHTML = 'Start Tests';
if (startButton.classList) {
startButton.classList.remove('pure-button-disabled');
}
}
};
runTest();
}, false);
document.getElementById('add-framework-form').addEventListener('submit', function(evt) {
var frameworkValue = document.getElementById('add-framework-value').value;
initFramework(frameworkValue);
initTests();
evt.preventDefault();
}, false);
</script>
</body>
</html>