-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_bench_test.go
52 lines (45 loc) · 1.31 KB
/
router_bench_test.go
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
package router
import (
"net/http"
"net/http/httptest"
"testing"
)
func BenchmarkRouter_ServeHTTP(b *testing.B) {
var routesList []Route
methodsList := []string{
http.MethodHead,
http.MethodGet,
http.MethodPost,
http.MethodPatch,
http.MethodPut,
http.MethodDelete,
http.MethodConnect,
http.MethodOptions,
http.MethodTrace,
}
dictionary := "abc1def2ghi3jkl4mno5pqr6stu7vwx8yz9_0-"
for _, method := range methodsList {
for _, symbol := range dictionary {
routesList = append(
routesList,
NewRoute("/"+string(symbol)+"test-example_high/load", method, handlerMock),
NewRoute("/"+string(symbol)+"test-example_high/load/route/test/help", method, handlerMock),
NewRoute("/"+string(symbol)+"test-example_high/load/route/test/help/test", method, handlerMock),
NewRoute("/"+string(symbol)+"test-example_high/load/route/test/exam/test/a", method, handlerMock),
)
}
}
routesList = append(
routesList,
NewRoute("/news/:id/comments/:id/statistics/test/test", http.MethodGet, handlerMock),
)
router := NewRouter()
router.AddRoutes(routesList)
b.ReportAllocs()
b.ResetTimer()
recorder := httptest.NewRecorder()
for i := 0; i < b.N; i++ {
request, _ := http.NewRequest(http.MethodGet, "/news/103/comments/10/statistics/test/test", nil)
router.ServeHTTP(recorder, request)
}
}