-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path2-closure.js
More file actions
34 lines (27 loc) · 786 Bytes
/
2-closure.js
File metadata and controls
34 lines (27 loc) · 786 Bytes
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
'use strict';
const memory = [];
const bytesToMb = (bytes) => Math.round(bytes / 1000, 2) / 1000;
const recursiveClosure = (a) => (fn) => recursiveClosure(a.map((g) => fn(g)));
let f = recursiveClosure(new Array(1000).fill((x) => x * 2));
const timer = setInterval(() => {
f = f((fn) => (x) => fn(x) * 2);
}, 5);
setInterval(() => {
console.clear();
const usage = process.memoryUsage();
const row = {
rss: bytesToMb(usage.rss),
heapTotal: bytesToMb(usage.heapTotal),
heapUsed: bytesToMb(usage.heapUsed),
external: bytesToMb(usage.external),
stack: bytesToMb(usage.rss - usage.heapTotal),
};
memory.push(row);
console.table(memory);
}, 1000);
setTimeout(() => {
clearInterval(timer);
}, 10000);
setTimeout(() => {
process.exit(0);
}, 15000);