forked from kripken/embenchen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
driver.js
138 lines (117 loc) · 4.26 KB
/
driver.js
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
function prettyNumber(x) {
x = '' + x;
var chars = x.split('');
var ret = '';
for (var i = 0; i < x.length; i++) {
if (i > 0 && i % 3 === 0) ret = ',' + ret;
ret = x[x.length-1-i] + ret;
}
return ret;
}
var jobs = [
{ title: 'micro-benchmarks' },
{ benchmark: 'copy' },
{ benchmark: 'corrections' },
{ benchmark: 'fannkuch' },
{ benchmark: 'fasta' },
{ benchmark: 'memops' },
{ benchmark: 'primes' },
{ benchmark: 'skinning' },
{ title: 'macro-benchmarks' },
{ benchmark: 'box2d' },
{ benchmark: 'bullet' },
{ benchmark: 'lua_binarytrees' },
{ benchmark: 'zlib' },
];
var ran = false;
function run() {
if (ran) return;
ran = true;
document.getElementById('results_area').hidden = false;
var tableBody = document.getElementById('table_body');
tableBody.innerHTML = '';
var theButton = document.getElementById('the_button');
theButton.innerHTML = 'Running benchmarks... (this can take a while)';
theButton.classList.remove('btn-primary');
theButton.classList.add('btn-warning');
var curr = 0;
function runJob() {
var job = jobs[curr++];
if (!job) {
theButton.classList.remove('btn-warning');
theButton.classList.add('btn-success');
theButton.innerHTML = 'Finished running benchmarks.';
return;
}
if (job.title) {
tableBody.innerHTML += '<tr>' +
' <td style="background-color:#ddd">' + job.title + '</td>' +
' <td style="background-color:#ddd"></td>' +
' <td style="background-color:#ddd"></td>' +
'</tr>';
setTimeout(runJob, 1);
return;
}
job.scale = job.scale || 'ms (lower numbers are better)';
tableBody.innerHTML += '<tr>' +
' <td>' + job.benchmark + '</td>' +
' <td id="' + job.benchmark + '-cell"><div id="' + job.benchmark + '-output" class="text-center"></div></td>' +
' <td>' + job.scale + '</td>' +
' <!--td id="' + job.benchmark + '-normalized-cell"><div id="' + job.benchmark + '-normalized-output" class="text-center"></div></td-->' +
'</tr>';
document.getElementById(job.benchmark + '-output').innerHTML = '<b>(..running..)</b>';
document.getElementById(job.benchmark + '-cell').style = 'background-color: #ffddaa';
// Run the job the specified number of times
var reps = 0;
var totalReps = 1;
var results = [];
function finish() {
console.log('final: ' + JSON.stringify(results));
var final = {};
for (var i = 0; i < totalReps; i++) {
var result = results[i];
for (var k in result) {
if (typeof result[k] === 'number') {
final[k] = (final[k] || 0) + result[k];
}
}
}
for (var k in final) {
if (typeof final[k] === 'number') {
final[k] /= totalReps;
}
}
job.msg = final;
console.log('final: ' + JSON.stringify(job.msg) + ' on ' + totalReps);
var raw = Math.round(job.msg.runtime);
var printable = prettyNumber(raw);
document.getElementById(job.benchmark + '-output').innerHTML = '<b>' + printable + '</b>';
document.getElementById(job.benchmark + '-cell').style = 'background-color: #bbccff';
//document.getElementById(job.benchmark + '-normalized-output').innerHTML = '<b>' + (raw/job.normalized).toFixed(3) + '</b>';
//document.getElementById(job.benchmark + '-normalized-cell').style = 'background-color: #ee9955';
setTimeout(runJob, 1);
}
function doRep() {
var worker = new Worker('worker.js');
worker.onmessage = function(event) {
var msg = event.data;
console.log(JSON.stringify(msg));
if (msg.benchmark != job.benchmark) throw 'invalid data from benchmark worker';
results.push(msg);
reps++;
if (reps === totalReps) {
worker.terminate(); // ensure the worker is cleaned up before the next starts
finish();
} else {
setTimeout(doRep, 1);
}
};
console.log('requesting benchmark ' + job.benchmark);
worker.postMessage({
benchmark: job.benchmark,
});
}
doRep();
}
runJob();
}