-
Notifications
You must be signed in to change notification settings - Fork 53
/
benchmark.js
32 lines (27 loc) · 708 Bytes
/
benchmark.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
const {readdirp} = require('./index.js');
function logMem(i) {
const vals = Object.entries(process.memoryUsage()).map(([k, v]) => {
return `${k}=${(`${(v / 1e6).toFixed(1)}M`).padEnd(7)}`;
});
console.log(String(i).padStart(6), ...vals);
}
const read = async (directory) => {
const stream = readdirp(directory, {type: 'all'});
let i = 0;
const start = Date.now();
let lap = 0;
let now = Date.now();
for await (const chunk of stream) {
if (i % 10000 === 0) {
now = Date.now();
if (now - lap > 500) {
lap = now;
logMem(i);
}
}
i++;
}
logMem(i);
console.log(`Processed ${i} files in ${Date.now() - start} msecs`);
};
read('../..');