-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhile.js
More file actions
31 lines (27 loc) · 688 Bytes
/
Copy pathwhile.js
File metadata and controls
31 lines (27 loc) · 688 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
import { interval, iteration } from "./const";
import { parse } from "./parse";
import printer from "./printer";
import sleep from "./sleep";
const benchmark = {
name: "WithWhile",
cpuUsage: [],
memUsage: [],
};
async function withWhile() {
let i = 0;
while (++i <= iteration) {
benchmark.cpuUsage.push(process.cpuUsage());
benchmark.memUsage.push(process.memoryUsage());
await sleep(interval);
printer("While");
}
}
(() => {
const start = Date.now();
console.log("While locked at ", start);
const p = withWhile();
p.then(() => {
console.log("Unlocked with ", (Date.now() - start) / 1000, "s");
console.table(parse(benchmark));
});
})();