-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeout.js
37 lines (33 loc) · 798 Bytes
/
timeout.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
import { interval, iteration } from "./const";
import { parse } from "./parse";
import printer from "./printer";
const benchmark = {
name: "WithTimeout",
cpuUsage: [],
memUsage: [],
};
function withTimeout() {
return new Promise((r) => {
const run = (i = 0) => {
setTimeout(() => {
benchmark.cpuUsage.push(process.cpuUsage());
benchmark.memUsage.push(process.memoryUsage());
if (i <= iteration) {
run(++i);
} else {
r(true);
}
}, interval);
};
run();
});
}
(() => {
const start = Date.now();
console.log("Timeout Locked at ", start);
const p = withTimeout();
p.then(() => {
console.log("Unlocked with ", (Date.now() - start) / 1000, "s");
console.table(parse(benchmark));
});
})();