Named groups replaced with conditional wrapping of regexps

This commit is contained in:
Tomasz Kłak
2016-01-23 17:42:00 +01:00
parent 26a6070f84
commit f48927253f
2 changed files with 44 additions and 34 deletions

View File

@@ -19,3 +19,16 @@ func BenchmarkMux(b *testing.B) {
router.ServeHTTP(nil, request)
}
}
func BenchmarkMuxAlternativeInRegexp(b *testing.B) {
router := new(Router)
handler := func(w http.ResponseWriter, r *http.Request) {}
router.HandleFunc("/v1/{v1:(a|b)}", handler)
requestA, _ := http.NewRequest("GET", "/v1/a", nil)
requestB, _ := http.NewRequest("GET", "/v1/b", nil)
for i := 0; i < b.N; i++ {
router.ServeHTTP(nil, requestA)
router.ServeHTTP(nil, requestB)
}
}