Skip to content

Commit 9ac1b68

Browse files
beeequeueaduh95
authored andcommitted
path: add benchmarks for path.matchesGlob()
Signed-off-by: Adam Haglund <adam@haglund.dev> PR-URL: #63915 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent f0b8a83 commit 9ac1b68

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { posix } = require('path');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
path: [
8+
'src/index.ts',
9+
'src/index.test.ts',
10+
'src/foo/bar/biz/baz/index.test.ts',
11+
],
12+
pattern: [
13+
'src/**/baz/*.test.ts',
14+
'src/**/baz/*.ts',
15+
'test/**/*.ts',
16+
],
17+
n: [1e5],
18+
});
19+
20+
function main({ path, pattern, n }) {
21+
bench.start();
22+
let a;
23+
for (let i = 0; i < n; i++) {
24+
a = posix.matchesGlob(path, pattern);
25+
}
26+
bench.end(n);
27+
assert(a + 'a');
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { win32 } = require('path');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
path: [
8+
'src/index.ts',
9+
'src\\index.ts',
10+
'src/foo/bar/biz/baz/index.test.ts',
11+
'src\\foo\\bar\\biz\\baz\\index.test.ts',
12+
],
13+
pattern: [
14+
'src/**/baz/*.test.ts',
15+
'src/**/baz/*.ts',
16+
'test/**/*.ts',
17+
],
18+
n: [1e5],
19+
});
20+
21+
function main({ path, pattern, n }) {
22+
bench.start();
23+
let a;
24+
for (let i = 0; i < n; i++) {
25+
a = win32.matchesGlob(path, pattern);
26+
}
27+
bench.end(n);
28+
assert(a + 'a');
29+
}

0 commit comments

Comments
 (0)