forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench-glob.js
More file actions
47 lines (37 loc) · 1.09 KB
/
bench-glob.js
File metadata and controls
47 lines (37 loc) · 1.09 KB
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
38
39
40
41
42
43
44
45
46
47
'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const benchmarkDirectory = path.resolve(__dirname, '..', '..');
const configs = {
n: [1, 10, 100],
dir: ['lib', 'test/parallel', 'benchmark'],
pattern: ['**/*', '*.js', '**/**.js'],
mode: ['async', 'sync'],
recursive: ['true', 'false'],
};
const bench = common.createBenchmark(main, configs);
async function main(config) {
const fullPath = path.resolve(benchmarkDirectory, config.dir);
const { pattern, recursive, mode } = config;
bench.start();
let counter = 0;
for (let i = 0; i < config.n; i++) {
if (mode === 'async') {
const matches = await new Promise((resolve, reject) => {
fs.glob(pattern, { cwd: fullPath, recursive }, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
};
});
});
counter += matches.length;
} else {
const matches = fs.globSync(pattern, { cwd: fullPath, recursive });
counter += matches.length;
}
}
bench.end(counter);
}