forked from sindresorhus/globby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
95 lines (90 loc) · 1.85 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
'use strict';
/* global after, before, bench, suite */
const fs = require('fs');
const rimraf = require('rimraf');
const globbyMainBranch = require('globby');
const gs = require('glob-stream');
const fastGlob = require('fast-glob');
const globby = require('.');
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);
['a', 'b']
.map(directory => `${directory}/`)
.forEach(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);
});
benchs.forEach(benchmark => {
suite(benchmark.name, () => {
runners.forEach(runner => bench(runner.name, runner.run.bind(null, benchmark.patterns)));
});
});