+28
-6
lines changedFilter options
+28
-6
lines changed Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
1
1
'use strict';
2
2
3
3
const common = require('../common');
4
-
const fs = require('fs');
4
+
const {
5
+
glob,
6
+
globSync,
7
+
promises: { glob: globAsync },
8
+
} = require('fs');
5
9
const path = require('path');
6
10
const assert = require('node:assert');
7
11
@@ -11,7 +15,7 @@ const configs = {
11
15
n: [1e3],
12
16
dir: ['lib'],
13
17
pattern: ['**/*', '*.js', '**/**.js'],
14
-
mode: ['async', 'sync'],
18
+
mode: ['sync', 'promise', 'callback'],
15
19
recursive: ['true', 'false'],
16
20
};
17
21
@@ -20,15 +24,33 @@ const bench = common.createBenchmark(main, configs);
20
24
async function main(config) {
21
25
const fullPath = path.resolve(benchmarkDirectory, config.dir);
22
26
const { pattern, recursive, mode } = config;
27
+
const options = { cwd: fullPath, recursive };
28
+
const callback = (resolve, reject) => {
29
+
glob(pattern, options, (err, matches) => {
30
+
if (err) {
31
+
reject(err);
32
+
} else {
33
+
resolve(matches);
34
+
}
35
+
});
36
+
};
23
37
24
38
let noDead;
25
39
bench.start();
26
40
27
41
for (let i = 0; i < config.n; i++) {
28
-
if (mode === 'async') {
29
-
noDead = await fs.promises.glob(pattern, { cwd: fullPath, recursive });
30
-
} else {
31
-
noDead = fs.globSync(pattern, { cwd: fullPath, recursive });
42
+
switch (mode) {
43
+
case 'sync':
44
+
noDead = globSync(pattern, options);
45
+
break;
46
+
case 'promise':
47
+
noDead = await globAsync(pattern, options);
48
+
break;
49
+
case 'callback':
50
+
noDead = await new Promise(callback);
51
+
break;
52
+
default:
53
+
throw new Error(`Unknown mode: ${mode}`);
32
54
}
33
55
}
34
56
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4