-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (98 loc) · 3.5 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
<!doctype>
<html>
<head>
<meta charset="UTF-8">
<title>wasm benchmark</title>
<style>
body {
background: #000;
color: #fff;
font-family: "Courier New", sans-serif;
font-size: 12px;
}
button {
background: none;
border: none;
color: #0094DE;
text-decoration: underline;
font-size: inherit;
}
li {
margin-bottom: 10px;
}
ol {
background: #000;
position: fixed;
right: 0;
font-size: 20px;
}
</style>
</head>
<body>
<ol>
<li><button onclick='load("b1")'>empty code</button></li>
<li><button onclick='load("b2")'>wasm alert("hello wasm")</button></li>
<li><button onclick='load("b3", 1, 1000, "iw")'>imported in-wasm futures (wait 1ms x1000 times)</button></li>
<li><button onclick='load("b3", 5, 200, "iw")'>imported in-wasm futures (wait 5ms x200 times)</button></li>
<li><button onclick='load("b4", 1, 1000, "st")'>setTimeout loop from js (wait 1ms x1000 times)</button></li>
<li><button onclick='load("b4", 5, 200, "st")'>setTimeout loop from js (wait 5ms x200 times)</button></li>
<li><button onclick='load("b4", 1, 1000, "si")'>setInterval loop from js (wait 1ms x1000 times)</button></li>
<li><button onclick='load("b4", 5, 200, "si")'>setInterval loop from js (wait 5ms x200 times)</button></li>
<li><button onclick='load("b5", 1, 1000, "iw")'>inline in-wasm futures (wait 1ms x1000 times)</button></li>
<li><button onclick='load("b5", 5, 200, "iw")'>inline in-wasm futures (wait 5ms x200 times)</button></li>
<a href='javascript:dlog(0,true)'>add line</a>
</ol>
</body>
<script>
function dlog(x, line=false) {
if (line) {
document.body.appendChild(document.createElement('hr'));
} else {
if (typeof x == "string")
document.body.append('"' + x + '"');
else
document.body.append(
(typeof x) + ': ' + Object.keys(x).toString());
document.body.appendChild(document.createElement('br'));
}
}
let start = new Date();
function tlog(pre) {
dlog(pre + (
(new Date()).getTime() - start.getTime()).toString() + 'ms');
start = new Date();
}
function sleep_impl(millis) {
return new Promise(resolve => {window.setTimeout(resolve, millis);});
}
function loop_it(r2, ms, rep) {
setTimeout(function() {
if (r2.myloop(rep)) {
loop_it(r2, ms, rep);
}
}, ms);
}
function loop_int(r2, ms, rep) {
let iid = setInterval(function() {
if (!r2.myloop(rep)) {
clearInterval(iid);
}
}, ms);
}
function load(x, ms=0, rep=0, si=null) {
tlog('begin running async: ');
let mod = import('./bin/' + x + '.js');
mod.then(r => {
wasm_bindgen('./bin/' + x + '_bg.wasm').then(r2 => {
if (x == 'b4') {
if (si == 'st') loop_it(r2, ms, rep);
else loop_int(r2, ms, rep);
} else if (si == 'iw') {
r2.entry(ms, rep);
}
tlog('end running async: ');
});
});
}
</script>
</html>