1 // Copyright 2012 The Gorilla Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func BenchmarkMux(b *testing.B) {
15 handler := func(w http.ResponseWriter, r *http.Request) {}
16 router.HandleFunc("/v1/{v1}", handler)
18 request, _ := http.NewRequest("GET", "/v1/anything", nil)
19 for i := 0; i < b.N; i++ {
20 router.ServeHTTP(nil, request)
24 func BenchmarkMuxAlternativeInRegexp(b *testing.B) {
26 handler := func(w http.ResponseWriter, r *http.Request) {}
27 router.HandleFunc("/v1/{v1:(?:a|b)}", handler)
29 requestA, _ := http.NewRequest("GET", "/v1/a", nil)
30 requestB, _ := http.NewRequest("GET", "/v1/b", nil)
31 for i := 0; i < b.N; i++ {
32 router.ServeHTTP(nil, requestA)
33 router.ServeHTTP(nil, requestB)
37 func BenchmarkManyPathVariables(b *testing.B) {
39 handler := func(w http.ResponseWriter, r *http.Request) {}
40 router.HandleFunc("/v1/{v1}/{v2}/{v3}/{v4}/{v5}", handler)
42 matchingRequest, _ := http.NewRequest("GET", "/v1/1/2/3/4/5", nil)
43 notMatchingRequest, _ := http.NewRequest("GET", "/v1/1/2/3/4", nil)
44 recorder := httptest.NewRecorder()
45 for i := 0; i < b.N; i++ {
46 router.ServeHTTP(nil, matchingRequest)
47 router.ServeHTTP(recorder, notMatchingRequest)