1
+ import { run , bench , group , baseline } from 'mitata' ;
2
+ import httpNext from './index'
3
+ import httpPrevious from '0http-bun'
4
+
5
+ function setupRouter ( router ) {
6
+ router . use ( ( req , next ) => {
7
+ return next ( )
8
+ } )
9
+
10
+ router . get ( '/' , ( ) => {
11
+ return new Response ( )
12
+ } )
13
+ router . get ( '/:id' , async ( req ) => {
14
+ return new Response ( req . params . id )
15
+ } )
16
+ router . get ( '/:id/error' , ( ) => {
17
+ throw new Error ( 'Error' )
18
+ } )
19
+ }
20
+
21
+ const { router } = httpNext ( )
22
+ setupRouter ( router )
23
+
24
+ const { router : routerPrevious } = httpPrevious ( )
25
+ setupRouter ( routerPrevious )
26
+
27
+ group ( 'Next Router' , ( ) => {
28
+ baseline ( 'Base URL' , ( ) => {
29
+ router . fetch ( new Request ( new URL ( 'http://localhost/' ) ) )
30
+ } )
31
+ bench ( 'Parameter URL' , ( ) => {
32
+ router . fetch ( new Request ( new URL ( 'http://localhost/0' ) ) )
33
+ } )
34
+ bench ( 'Not Found URL' , ( ) => {
35
+ router . fetch ( new Request ( new URL ( 'http://localhost/0/404' ) ) )
36
+ } )
37
+ bench ( 'Error URL' , ( ) => {
38
+ router . fetch ( new Request ( new URL ( 'http://localhost/0/error' ) ) )
39
+ } )
40
+ } )
41
+
42
+ group ( 'Previous Router' , ( ) => {
43
+ baseline ( 'Base URL' , ( ) => {
44
+ routerPrevious . fetch ( new Request ( new URL ( 'http://localhost/' ) ) )
45
+ } )
46
+ bench ( 'Parameter URL' , ( ) => {
47
+ routerPrevious . fetch ( new Request ( new URL ( 'http://localhost/0' ) ) )
48
+ } )
49
+ bench ( 'Not Found URL' , ( ) => {
50
+ routerPrevious . fetch ( new Request ( new URL ( 'http://localhost/0/404' ) ) )
51
+ } )
52
+ bench ( 'Error URL' , ( ) => {
53
+ routerPrevious . fetch ( new Request ( new URL ( 'http://localhost/0/error' ) ) )
54
+ } )
55
+ } )
56
+
57
+ await run ( {
58
+ silent : false ,
59
+ avg : true ,
60
+ json : false ,
61
+ colors : true ,
62
+ min_max : false ,
63
+ percentiles : false
64
+ } )
0 commit comments