-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval.js
More file actions
37 lines (32 loc) · 806 Bytes
/
Copy pathinterval.js
File metadata and controls
37 lines (32 loc) · 806 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
35
36
37
import { interval, iteration } from "./const";
import { parse } from "./parse";
import printer from "./printer";
const benchmark = {
name: "WithInterval",
cpuUsage: [],
memUsage: [],
};
async function withInterval() {
return new Promise((r) => {
let i = 0;
const iv = setInterval(() => {
++i;
benchmark.cpuUsage.push(process.cpuUsage());
benchmark.memUsage.push(process.memoryUsage());
printer("setInterval");
if (i >= iteration) {
clearInterval(iv);
r(true);
}
}, interval);
});
}
(() => {
const start = Date.now();
console.log("Interval locked at ", start);
const p = withInterval();
p.then(() => {
console.log("Unlocked with ", (Date.now() - start) / 1000, "s");
console.table(parse(benchmark));
});
})();