-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-memory.js
30 lines (26 loc) · 873 Bytes
/
test-memory.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
import {toBytes, toBase64} from './small.js';
import {toBase64Simple} from './alternative.js';
// not quite sure if freeing memory really works and how to best test it
// at least memory stays at higher levels if removing free()
setInterval(() => {
console.log(
'heap size (MB)',
performance.memory.usedJSHeapSize >> 20,
performance.memory.totalJSHeapSize >> 20
);
}, 250);
let i = 0;
setInterval(() => {
if (i % 4 === 0) toBytes(randomBase64(10000000)[0]);
if (i % 4 === 1) toBase64(randomBase64(10000000)[1]);
if (i % 4 === 2) toBytes(randomBase64(100000)[0]);
if (i % 4 === 3) toBase64(randomBase64(100000)[1]);
i++;
}, 5000);
function randomBase64(n) {
const randomBytes = new Uint8Array(n);
for (let i = 0; i < n; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return [toBase64Simple(randomBytes), randomBytes];
}