-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
bench.js
98 lines (93 loc) · 1.98 KB
/
bench.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* global after, before, bench, suite */
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import rimraf from 'rimraf';
import globbyMainBranch from 'globby';
import gs from 'glob-stream';
import fastGlob from 'fast-glob';
import globby from './index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const BENCH_DIR = 'bench';
const runners = [{
name: 'globby async (working directory)',
run: async (patterns, callback) => {
await globby(patterns);
callback();
},
}, {
name: 'globby async (upstream/main)',
run: async (patterns, callback) => {
await globbyMainBranch(patterns);
callback();
},
}, {
name: 'globby sync (working directory)',
run: patterns => {
globby.sync(patterns);
},
}, {
name: 'globby sync (upstream/main)',
run: patterns => {
globbyMainBranch.sync(patterns);
},
}, {
name: 'glob-stream',
run: (patterns, cb) => {
gs(patterns).on('data', () => {}).on('end', cb);
},
}, {
name: 'fast-glob async',
run: async (patterns, callback) => {
await fastGlob(patterns);
callback();
},
}, {
name: 'fast-glob sync',
run: patterns => {
fastGlob.sync(patterns);
},
}];
const benchs = [{
name: 'negative globs (some files inside dir)',
patterns: [
'a/*',
'!a/c*',
],
}, {
name: 'negative globs (whole dir)',
patterns: [
'a/*',
'!a/**',
],
}, {
name: 'multiple positive globs',
patterns: [
'a/*',
'b/*',
],
}];
before(() => {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
fs.mkdirSync(BENCH_DIR);
process.chdir(BENCH_DIR);
for (const directory of ['a', 'b']
.map(directory => `${directory}/`)) {
fs.mkdirSync(directory);
for (let i = 0; i < 500; i++) {
fs.writeFileSync(directory + (i < 100 ? 'c' : 'd') + i, '');
}
}
});
after(() => {
process.chdir(__dirname);
rimraf.sync(BENCH_DIR);
});
for (const benchmark of benchs) {
suite(benchmark.name, () => {
for (const runner of runners) {
bench(runner.name, runner.run.bind(null, benchmark.patterns));
}
});
}