1
- 'use strict'
1
+ 'use strict' ;
2
2
3
- const { now , print , operations } = require ( './util' )
4
- const KoaRouter = require ( '../lib/router' )
3
+ const KoaRouter = require ( '../lib/router' ) ;
4
+ const { now , print , operations } = require ( './util' ) ;
5
5
6
- const router = new KoaRouter ( )
6
+ const router = new KoaRouter ( ) ;
7
7
8
8
const routes = [
9
9
{ method : 'GET' , url : '/user' } ,
@@ -18,66 +18,73 @@ const routes = [
18
18
{ method : 'GET' , url : '/status' } ,
19
19
{ method : 'GET' , url : '/very/deeply/nested/route/hello/there' } ,
20
20
{ method : 'GET' , url : '/static/(.*)' }
21
- ]
21
+ ] ;
22
22
23
- function noop ( ) { }
23
+ function noop ( ) { }
24
24
25
- var i = 0
26
- var time = 0
25
+ let i = 0 ;
26
+ let time = 0 ;
27
27
28
- routes . forEach ( route => {
28
+ for ( const route of routes ) {
29
29
if ( route . method === 'GET' ) {
30
- router . get ( route . url , noop )
30
+ router . get ( route . url , noop ) ;
31
31
} else {
32
- router . post ( route . url , noop )
32
+ router . post ( route . url , noop ) ;
33
33
}
34
- } )
34
+ }
35
35
36
- time = now ( )
36
+ time = now ( ) ;
37
37
for ( i = 0 ; i < operations ; i ++ ) {
38
- router . match ( '/user' , 'GET' )
38
+ router . match ( '/user' , 'GET' ) ;
39
39
}
40
- print ( 'short static:' , time )
41
40
42
- time = now ( )
41
+ print ( 'short static:' , time ) ;
42
+
43
+ time = now ( ) ;
43
44
for ( i = 0 ; i < operations ; i ++ ) {
44
- router . match ( '/user/comments' , 'GET' )
45
+ router . match ( '/user/comments' , 'GET' ) ;
45
46
}
46
- print ( 'static with same radix:' , time )
47
47
48
- time = now ( )
48
+ print ( 'static with same radix:' , time ) ;
49
+
50
+ time = now ( ) ;
49
51
for ( i = 0 ; i < operations ; i ++ ) {
50
- router . match ( '/user/lookup/username/john' , 'GET' )
52
+ router . match ( '/user/lookup/username/john' , 'GET' ) ;
51
53
}
52
- print ( 'dynamic route:' , time )
53
54
54
- time = now ( )
55
+ print ( 'dynamic route:' , time ) ;
56
+
57
+ time = now ( ) ;
55
58
for ( i = 0 ; i < operations ; i ++ ) {
56
- router . match ( '/event/abcd1234/comments' , 'GET' )
59
+ router . match ( '/event/abcd1234/comments' , 'GET' ) ;
57
60
}
58
- print ( 'mixed static dynamic:' , time )
59
61
60
- time = now ( )
62
+ print ( 'mixed static dynamic:' , time ) ;
63
+
64
+ time = now ( ) ;
61
65
for ( i = 0 ; i < operations ; i ++ ) {
62
- router . match ( '/very/deeply/nested/route/hello/there' , 'GET' )
66
+ router . match ( '/very/deeply/nested/route/hello/there' , 'GET' ) ;
63
67
}
64
- print ( 'long static:' , time )
65
68
66
- time = now ( )
69
+ print ( 'long static:' , time ) ;
70
+
71
+ time = now ( ) ;
67
72
for ( i = 0 ; i < operations ; i ++ ) {
68
- router . match ( '/static/index.html' , 'GET' )
73
+ router . match ( '/static/index.html' , 'GET' ) ;
69
74
}
70
- print ( 'wildcard:' , time )
71
75
72
- time = now ( )
76
+ print ( 'wildcard:' , time ) ;
77
+
78
+ time = now ( ) ;
73
79
for ( i = 0 ; i < operations ; i ++ ) {
74
- router . match ( '/user' , 'GET' )
75
- router . match ( '/user/comments' , 'GET' )
76
- router . match ( '/user/lookup/username/john' , 'GET' )
77
- router . match ( '/event/abcd1234/comments' , 'GET' )
78
- router . match ( '/very/deeply/nested/route/hello/there' , 'GET' )
79
- router . match ( '/static/index.html' , 'GET' )
80
+ router . match ( '/user' , 'GET' ) ;
81
+ router . match ( '/user/comments' , 'GET' ) ;
82
+ router . match ( '/user/lookup/username/john' , 'GET' ) ;
83
+ router . match ( '/event/abcd1234/comments' , 'GET' ) ;
84
+ router . match ( '/very/deeply/nested/route/hello/there' , 'GET' ) ;
85
+ router . match ( '/static/index.html' , 'GET' ) ;
80
86
}
81
- const output = print ( 'all together:' , time )
82
87
83
- require ( 'fs' ) . writeFileSync ( 'bench-result.txt' , String ( output ) )
88
+ const output = print ( 'all together:' , time ) ;
89
+
90
+ require ( 'fs' ) . writeFileSync ( 'bench-result.txt' , String ( output ) ) ;
0 commit comments