-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.ts
53 lines (46 loc) · 1.27 KB
/
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
import { run, bench, group } from "mitata";
import httpNext from "./index";
import httpPrevious from "0http-bun";
function setupRouter(router) {
router.use((req, next) => {
return next();
});
router.get("/", () => {
return new Response();
});
router.get("/:id", async (req) => {
return new Response(req.params.id);
});
router.get("/:id/error", () => {
throw new Error("Error");
});
}
const { router } = httpNext();
setupRouter(router);
const { router: routerPrevious } = httpPrevious();
setupRouter(routerPrevious);
group("Next Router", () => {
bench("Parameter URL", () => {
router.fetch(new Request(new URL("http://localhost/0")));
});
bench("Not Found URL", () => {
router.fetch(new Request(new URL("http://localhost/0/404")));
});
bench("Error URL", () => {
router.fetch(new Request(new URL("http://localhost/0/error")));
});
});
group("Previous Router", () => {
bench("Parameter URL", () => {
routerPrevious.fetch(new Request(new URL("http://localhost/0")));
});
bench("Not Found URL", () => {
routerPrevious.fetch(new Request(new URL("http://localhost/0/404")));
});
bench("Error URL", () => {
routerPrevious.fetch(new Request(new URL("http://localhost/0/error")));
});
});
await run({
colors: true,
});