Skip to content

Commit 9f9c6c5

Browse files
authored
Add parsing to benchmarks (#418)
1 parent 9fd31e0 commit 9f9c6c5

1 file changed

Lines changed: 56 additions & 39 deletions

File tree

src/index.bench.ts

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
1-
import { bench } from "vitest";
2-
import { match } from "./index.js";
3-
4-
const PATHS: string[] = [
5-
"/xyz",
6-
"/user",
7-
"/user/123",
8-
"/" + "a".repeat(32_000),
9-
"/-" + "-a".repeat(8_000) + "/-",
10-
"/||||\x00|" + "||".repeat(27387) + "|\x00".repeat(27387) + "/||/",
11-
];
12-
13-
const STATIC_PATH_MATCH = match("/user");
14-
const SIMPLE_PATH_MATCH = match("/user/:id");
15-
const MULTI_SEGMENT_MATCH = match("/:x/:y");
16-
const MULTI_PATTERN_MATCH = match("/:x-:y");
17-
const TRICKY_PATTERN_MATCH = match("/:foo|:bar|");
18-
const ASTERISK_MATCH = match("/*foo");
19-
20-
bench("static path", () => {
21-
for (const path of PATHS) STATIC_PATH_MATCH(path);
1+
import { describe, bench } from "vitest";
2+
import { match, parse } from "./index.js";
3+
4+
describe("parse", () => {
5+
const PATHS: string[] = [
6+
"/api",
7+
"/user/:id",
8+
"/files/*filepath",
9+
"/:foo-:bar",
10+
'/quoted-:"param"',
11+
"/complex/:param1-:param2/*rest",
12+
];
13+
14+
bench("parsing paths", () => {
15+
for (const path of PATHS) parse(path);
16+
});
2217
});
2318

24-
bench("simple path", () => {
25-
for (const path of PATHS) SIMPLE_PATH_MATCH(path);
26-
});
27-
28-
bench("multi segment", () => {
29-
for (const path of PATHS) MULTI_SEGMENT_MATCH(path);
30-
});
31-
32-
bench("multi pattern", () => {
33-
for (const path of PATHS) MULTI_PATTERN_MATCH(path);
34-
});
35-
36-
bench("tricky pattern", () => {
37-
for (const path of PATHS) TRICKY_PATTERN_MATCH(path);
38-
});
39-
40-
bench("asterisk", () => {
41-
for (const path of PATHS) ASTERISK_MATCH(path);
19+
describe("match", () => {
20+
const PATHS: string[] = [
21+
"/xyz",
22+
"/user",
23+
"/user/123",
24+
"/" + "a".repeat(32_000),
25+
"/-" + "-a".repeat(8_000) + "/-",
26+
"/||||\x00|" + "||".repeat(27387) + "|\x00".repeat(27387) + "/||/",
27+
];
28+
29+
const STATIC_PATH_MATCH = match("/user");
30+
const SIMPLE_PATH_MATCH = match("/user/:id");
31+
const MULTI_SEGMENT_MATCH = match("/:x/:y");
32+
const MULTI_PATTERN_MATCH = match("/:x-:y");
33+
const TRICKY_PATTERN_MATCH = match("/:foo|:bar|");
34+
const ASTERISK_MATCH = match("/*foo");
35+
36+
bench("static path", () => {
37+
for (const path of PATHS) STATIC_PATH_MATCH(path);
38+
});
39+
40+
bench("simple path", () => {
41+
for (const path of PATHS) SIMPLE_PATH_MATCH(path);
42+
});
43+
44+
bench("multi segment", () => {
45+
for (const path of PATHS) MULTI_SEGMENT_MATCH(path);
46+
});
47+
48+
bench("multi pattern", () => {
49+
for (const path of PATHS) MULTI_PATTERN_MATCH(path);
50+
});
51+
52+
bench("tricky pattern", () => {
53+
for (const path of PATHS) TRICKY_PATTERN_MATCH(path);
54+
});
55+
56+
bench("asterisk", () => {
57+
for (const path of PATHS) ASTERISK_MATCH(path);
58+
});
4259
});

0 commit comments

Comments
 (0)