Repository navigation
Expand file tree
/
Copy pathbench.ts
More file actions
105 lines (76 loc) · 3.28 KB
/
Copy pathbench.ts
File metadata and controls
105 lines (76 loc) · 3.28 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
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
99
100
101
102
103
104
105
import { matchesGlob } from "node:path"
import micromatch from "micromatch"
import { Minimatch } from "minimatch"
import { barplot, bench, group, run, summary } from "mitata"
import picomatch from "picomatch"
import zepto from "zeptomatch"
import pkgJson from "./package.json" with { type: "json" }
const MINIMATCH = `minimatch@${pkgJson.dependencies.minimatch}`
const PICOMATCH = `picomatch@${pkgJson.dependencies.picomatch}`
const MICROMATCH = `micromatch@${pkgJson.dependencies.micromatch}`
const ZEPTOMATCH = `zeptomatch@${pkgJson.dependencies.zeptomatch}`
const NODEPATHMATCH = `node:path@${process.versions.node}`
// const MEMOIZED_NODEPATHMATCH = `node:path@${process.versions.node} (memoized)`
// const createMemoizedMatchesGlob = () => {
// const cache = new Map<string, boolean>()
// const memoizedMatchesGlob = (path: string, glob: string): boolean => {
// const key = `${path}:${glob}`
// if (cache.has(key)) return cache.get(key)!
//
// const result = matchesGlob(path, glob)
// cache.set(key, result)
// return result
// }
//
// return memoizedMatchesGlob
// }
barplot(() => {
summary(() => {
group("match single file with a short path", () => {
const path = "src/index.test.ts"
const glob = "src/**/*.ts"
const pico = picomatch(glob)
bench(PICOMATCH, () => pico(path))
const micro = micromatch.matcher(glob)
bench(MICROMATCH, () => micro(path))
bench(ZEPTOMATCH, () => zepto(glob, path))
const mini = new Minimatch(glob)
bench(MINIMATCH, () => mini.match(path))
bench("minimatch no-reuse (node 26)", () => new Minimatch(glob).match(path))
bench(NODEPATHMATCH, () => matchesGlob(path, glob))
// const memoizedMatchesGlob = createMemoizedMatchesGlob()
// bench(MEMOIZED_NODEPATHMATCH, () => memoizedMatchesGlob(path, glob))
})
group("match single file with a long path", () => {
const path = "src/foo/bar/biz/baz/index.test.ts"
const glob = "src/**/baz/*.test.ts"
const pico = picomatch(glob)
bench(PICOMATCH, () => pico(path))
const micro = micromatch.matcher(glob)
bench(MICROMATCH, () => micro(path))
bench(ZEPTOMATCH, () => zepto(glob, path))
const mini = new Minimatch(glob)
bench(MINIMATCH, () => mini.match(path))
bench("minimatch no-reuse (node 26)", () => new Minimatch(glob).match(path))
bench(NODEPATHMATCH, () => matchesGlob(path, glob))
// const memoizedMatchesGlob = createMemoizedMatchesGlob()
// bench(MEMOIZED_NODEPATHMATCH, () => memoizedMatchesGlob(path, glob))
})
group("no match", () => {
const path = "tests/foo/bar/index.test.ts"
const glob = "src/**/*.test.ts"
const pico = picomatch(glob)
bench(PICOMATCH, () => pico(path))
const micro = micromatch.matcher(glob)
bench(MICROMATCH, () => micro(path))
bench(ZEPTOMATCH, () => zepto(glob, path))
const mini = new Minimatch(glob)
bench(MINIMATCH, () => mini.match(path))
bench("minimatch no-reuse (node 26)", () => new Minimatch(glob).match(path))
bench(NODEPATHMATCH, () => matchesGlob(path, glob))
// const memoizedMatchesGlob = createMemoizedMatchesGlob()
// bench(MEMOIZED_NODEPATHMATCH, () => memoizedMatchesGlob(path, glob))
})
})
})
await run()