-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmarks_test.go
115 lines (79 loc) · 2.58 KB
/
benchmarks_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package muxter
import (
"net/http"
"net/http/httptest"
"testing"
)
func BenchmarkSTD(b *testing.B) {
mux := http.NewServeMux()
rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
mux.HandleFunc("/some/deeply/nested/path/id", func(rw http.ResponseWriter, r *http.Request) {})
b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.ServeHTTP(rw, r)
}
}
func BenchmarkRouting(b *testing.B) {
mux := New()
mux.HandleFunc("/some/deeply/nested/path/id", func(rw http.ResponseWriter, r *http.Request, c Context) {})
rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.ServeHTTP(rw, r)
}
}
func BenchmarkStandardRouting(b *testing.B) {
mux := New()
mux.StandardHandle("/some/deeply/nested/path/id", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {}))
rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.ServeHTTP(rw, r)
}
}
func BenchmarkAdaptorNoContextRouting(b *testing.B) {
mux := New()
hander := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {})
mux.Handle("/some/deeply/nested/path/id", Adaptor(hander, NoContext))
rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.ServeHTTP(rw, r)
}
}
func BenchmarkRoutingParams(b *testing.B) {
mux := New()
mux.HandleFunc("/some/deeply/:nested/path/:id", func(rw http.ResponseWriter, r *http.Request, c Context) {})
rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.ServeHTTP(rw, r)
}
}
// func BenchmarkRoutingParamsHttpRouter(b *testing.B) {
// mux := httprouter.New()
// mux.GET("/some/deeply/:nested/path/:id", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {})
// rw := httptest.NewRecorder()
// r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
// b.ResetTimer()
// for i := 0; i < b.N; i++ {
// mux.ServeHTTP(rw, r)
// }
// }
func BenchmarkRoutingParamsNestedMuxes(b *testing.B) {
child := New()
child.HandleFunc("/path/:id", func(w http.ResponseWriter, r *http.Request, c Context) {})
root := New()
root.Handle("/some/deeply/:nested/", StripDepth(3, child))
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/some/deeply/nested/path/id", nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
root.ServeHTTP(w, r)
}
}