-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.js
37 lines (30 loc) · 882 Bytes
/
shared.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
const USE_TRANSFERABLE = true;
const USE_LONG_LIVED_CONNECTION = false;
const SIZE = 1024 * 1024 * 32; // 32MB
let arrayBuffer = null;
let uInt8View = null;
let originalLength = null;
function setupArray(source) {
arrayBuffer = new ArrayBuffer(SIZE);
uInt8View = new Uint8Array(arrayBuffer);
originalLength = uInt8View.length;
for (let i = 0; i < originalLength; ++i) {
uInt8View[i] = i;
}
console.log(source + ': filled ' + toMB(originalLength) + ' MB buffer');
}
function time() {
let now = new Date();
let time = /(\d+:\d+:\d+)/.exec(now)[0] + ':';
let ms, i;
for (ms = String(now.getMilliseconds()), i = ms.length - 3; i < 0; ++i) {
time += '0';
}
return time + ms;
}
function seconds(since) {
return (new Date() - since) / 1000.0;
}
function toMB(bytes) {
return Math.round(bytes / 1024 / 1024);
}