-
Notifications
You must be signed in to change notification settings - Fork 2
/
routing.bench.ts
74 lines (62 loc) · 1.43 KB
/
routing.bench.ts
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
import { pathToRegexp as pathToRegexp7 } from "npm:path-to-regexp@7.0.0";
import { pathToRegexp as pathToRegexp71 } from "npm:path-to-regexp@7.1.0";
import { pathToRegexp as pathToRegexp8 } from "npm:path-to-regexp@8.2.0";
import { pathToRegexp } from "npm:path-to-regexp@6.2.1";
import { URLPattern as URLPatternPolyfill } from "npm:urlpattern-polyfill@10.0.0";
const urlPatternPolyfill = new URLPatternPolyfill(
"/book/:id",
"http://localhost/",
);
Deno.bench({
name: "URLPattern polyfill",
fn() {
if (urlPatternPolyfill.exec("http://localhost/book/1234")) {
true;
}
},
});
const urlPattern = new URLPattern("/book/:id", "http://localhost/");
Deno.bench({
name: "URLPattern",
fn() {
if (urlPattern.exec("http://localhost/book/1234")) {
true;
}
},
});
const regexp = pathToRegexp("/:id");
Deno.bench({
name: "pathToRegexp 6.2",
fn() {
if (regexp.exec("/1234")) {
true;
}
},
});
const regexp7 = pathToRegexp7("/book/:id");
Deno.bench({
name: "pathToRegexp 7.0",
fn() {
if (regexp7.exec("/book/1234")) {
true;
}
},
});
const regexp71 = pathToRegexp71("/book/:id", { strict: true });
Deno.bench({
name: "pathToRegexp 7.1",
fn() {
if (regexp71.exec("/book/1234")) {
true;
}
},
});
const { regexp: regexp8 } = pathToRegexp8("/book/:id");
Deno.bench({
name: "pathToRegexp 8",
fn() {
if (regexp8.exec("/book/1234")) {
true;
}
},
});