-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
234 lines (214 loc) · 6.76 KB
/
index.html
File metadata and controls
234 lines (214 loc) · 6.76 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Faster Browser Code</title>
<link type="text/css" href="styles.css" media="screen" rel="Stylesheet" />
<script type="text/javascript" src="tests/webgl_glsl/benchmark.js"></script>
<script type="text/javascript" src="tests/pnacl_cpp/common.js"></script>
<script type="text/javascript" src="tests/pnacl_cpp/benchmark.js"></script>
</head>
<body data-name="fibonacci" data-tools="pnacl newlib glibc clang-newlib linux" data-configs="Debug Release" data-path="tests/pnacl_cpp/{tc}/{config}">
<span id="forkongithub">
<a href="https://github.com/SoftwareAddictionShow/faster-browser-code">Fork me on GitHub</a>
</span>
<h1>Faster Browser Code</h1>
<p>
This application benchmarks different web technologies. The goal
is to see which is faster than vanilla JavaScript. The function
fibonacci(43) is run in each benchmark.
</p>
<h2>Benchmarks:</h2>
<p>
<button id="start">Start Benchmarks</button>
<span id="waiting" style="display: none;" class="running">Running benchmarks ...</span>
</p>
<table>
<tr>
<th>Technology</th>
<th>Description</th>
<th>Fib(43) in ms</th>
<th>Score</th>
</tr>
<tr>
<td>JavaScript</td>
<td>Simple JavaScript function.</td>
<td class="result_time"><span id="time_js_pure"></span></td>
<td class="result_time" id="diff_js_pure"></td>
</tr>
<tr>
<td>JavaScript - "use strict"</td>
<td>JavaScript function with the "use strict" directive.</td>
<td class="result_time"><span id="time_js_use_strict"></span></td>
<td class="result_time" id="diff_js_use_strict"></td>
</tr>
<tr>
<td>JavaScript - "bitwise or" on variables</td>
<td>
JavaScript function with "bitwise or" (n | 0) after variables.
This truncates the variables to whole numbers, and lets the
browser known it can treat all the floats as integers (Even
though JavaScript does not support integers).
</td>
<td class="result_time"><span id="time_js_bitwise_or_integers"></span></td>
<td class="result_time" id="diff_js_bitwise_or_integers"></td>
</tr>
<tr>
<td>Emscripten - C</td>
<td>C compiled with Emscripten on default settings.</td>
<td class="result_time"><span id="time_emscripten_c"></span></td>
<td class="result_time" id="diff_emscripten_c"></td>
</tr>
<tr>
<td>Emscripten - C with -O3</td>
<td>C compiled with Emscripten on optimized(-O3) settings.</td>
<td class="result_time"><span id="time_emscripten_c_o3"></span></td>
<td class="result_time" id="diff_emscripten_c_o3"></td>
</tr>
<tr>
<td>WebGL - GLSL</td>
<td>GLGL running on the GPU via WebGL (OpenGL)</td>
<td class="result_time"><span id="time_webgl_glsl"></span></td>
<td class="result_time" id="diff_webgl_glsl"></td>
</tr>
<tr>
<td>Cheerp - C++</td>
<td>C++ compiled with Cheerp on optimized(-O3) settings.</td>
<td class="result_time"><span id="time_cheerp_cpp"></span></td>
<td class="result_time" id="diff_cheerp_cpp"></td>
</tr>
<tr>
<td>PNaCl - C++</td>
<td>C++ compiled with PNaCl on default optimized(-O2) settings.</td>
<td class="result_time"><span id="time_pnacl_cpp"></span></td>
<td class="result_time" id="diff_pnacl_cpp"></td>
</tr>
</table>
<h2>TODO:</h2>
<ul>
<li>Emscripten - C with Closure Compiler</li>
<li>Emscripten - C++</li>
<li>ASM.js</li>
<li>TypeScript</li>
<li>CoffeeScript</li>
<li>Swift</li>
<li>Hax</li>
<li>C# - JSIL</li>
<li>Go - gopherjs</li>
</ul>
<h2>TODO Browser Dependent:</h2>
<ul>
<li>Dart</li>
<li>Nacl</li>
</ul>
<h2>TODO Future:</h2>
<ul>
<li>WebAssembly - C++</li>
<li>JavaScript - SIMD</li>
<li>OpenCL</li>
<li>WebCL</li>
</ul>
<div id="listener"></div>
</body>
<script>
var g_benchmarks = [
{name: 'js_pure', use_worker: true},
{name: 'js_use_strict', use_worker: true},
{name: 'js_bitwise_or_integers', use_worker: true},
{name: 'emscripten_c', use_worker: true},
{name: 'emscripten_c_o3', use_worker: true},
{name: 'webgl_glsl', use_worker: false, cb: benchmarkWebGlGLSL},
{name: 'cheerp_cpp', use_worker: true},
{name: 'pnacl_cpp', use_worker: false, cb: benchmarkPNaCl},
];
// FIXME: rename to getScore
function withPositiveOrNegative(new_time, base_score) {
var new_time = new_time - base_score;
var prefix = '';
if (new_time > 0) {
prefix = '+'
} else if (new_time < 0) {
prefix = '-';
}
return prefix + ((Math.abs(new_time) / Math.abs(base_score)) * 100).toFixed(2) + '%';
}
function runBenchmarkInWorker(worker_path, cb) {
console.info(worker_path);
var worker = new Worker(worker_path);
worker.onmessage = function(e) {
switch (e.data.action) {
case 'end':
var start_time = e.data.start_time;
var result = e.data.result;
var end_time = e.data.end_time;
var diff_time = end_time - start_time;
cb(diff_time, result);
worker.terminate();
break;
}
};
var message = {
action: 'start'
};
worker.postMessage(message);
}
function startBenchmarks() {
var base_score = 0;
var i = 0;
var time_span = null;
// FIXME: rename to score_span
var diff_span = null;
var onStart = function() {
document.querySelector('#start').style.display = 'none';
document.querySelector('#waiting').style.display = '';
};
var onEnd = function() {
document.querySelector('#start').style.display = '';
document.querySelector('#waiting').style.display = 'none';
};
var onBenchmarkEnd = function(diff_time, result) {
if (i === 0) {
base_score = diff_time;
}
time_span.classList.remove('running');
if (diff_time !== null) {
time_span.innerHTML = diff_time;
diff_span.innerHTML = withPositiveOrNegative(diff_time, base_score);
} else {
time_span.innerHTML = 'Failed';
diff_span.innerHTML = 'Failed';
}
i++;
nextBenchmark();
};
var nextBenchmark = function() {
if (i === 0) {
onStart();
} else if (i >= g_benchmarks.length) {
onEnd();
return;
}
var bench_name = g_benchmarks[i]['name'];
var use_worker = g_benchmarks[i]['use_worker'];
time_span = document.querySelector('#time_' + bench_name);
diff_span = document.querySelector('#diff_' + bench_name);
time_span.classList.add('running');
time_span.innerHTML = 'Running ...';
diff_span.innerHTML = '';
setTimeout(function() {
if (use_worker) {
var worker_path = 'tests/' + bench_name + '/worker.js';
runBenchmarkInWorker(worker_path, onBenchmarkEnd);
} else {
var cb = g_benchmarks[i]['cb'];
cb(onBenchmarkEnd);
}
}, 100);
};
nextBenchmark();
}
document.querySelector('#start').addEventListener('click', function() {
startBenchmarks();
}, false);
</script>
</html>