-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
42 lines (36 loc) · 1 KB
/
Copy pathshared.js
File metadata and controls
42 lines (36 loc) · 1 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
var USE_TRANSFERABLE = true,
SIZE = 1024 * 1024, // 32MB
arrayBuffer = null,
uInt8View = null,
originalLength = null;
function setupArray() {
arrayBuffer = new ArrayBuffer(SIZE * size);
uInt8View = new Uint8Array(arrayBuffer);
originalLength = uInt8View.length;
for (var i = 0; i < originalLength; ++i) {
uInt8View[i] = i;
}
log(source() + 'filled ' + toMB(originalLength) + ' MB buffer');
}
function time() {
var now = new Date(),
time = /(\d+:\d+:\d+)/.exec(now)[0] + ':';
for (var ms = String(now.getMilliseconds()), i = ms.length - 3; i < 0; ++i) {
time += '0';
}
return time + ms;
}
function source(s) {
if (self.importScripts) {
return '<span style="color:red;">worker:</span> ';
} else {
return '<span style="color:green;">thread:</span> ';
}
}
function toMB(bytes) {
if (size >= 1) {
return (bytes / 1024 / 1024).toFixed();
} else {
return (bytes / 1024 / 1024).toFixed(5);
}
}