(b *testing.B, routes []testRoute, routesToFind []testRoute)
| 2882 | } |
| 2883 | |
| 2884 | func benchmarkRouterRoutes(b *testing.B, routes []testRoute, routesToFind []testRoute) { |
| 2885 | e := New() |
| 2886 | r := e.router |
| 2887 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 2888 | b.ReportAllocs() |
| 2889 | |
| 2890 | // Add routes |
| 2891 | for _, route := range routes { |
| 2892 | e.AddRoute(Route{ |
| 2893 | Method: route.Method, |
| 2894 | Path: route.Path, |
| 2895 | Handler: func(c *Context) error { |
| 2896 | return nil |
| 2897 | }, |
| 2898 | }) |
| 2899 | } |
| 2900 | |
| 2901 | // Routes adding are performed just once, so it doesn't make sense to see that in the benchmark |
| 2902 | b.ResetTimer() |
| 2903 | |
| 2904 | // Find routes |
| 2905 | for i := 0; i < b.N; i++ { |
| 2906 | for _, route := range routesToFind { |
| 2907 | c := e.contextPool.Get().(*Context) |
| 2908 | c.request = req |
| 2909 | |
| 2910 | req.Method = route.Method |
| 2911 | req.URL.Path = route.Path |
| 2912 | |
| 2913 | _ = r.Route(c) |
| 2914 | |
| 2915 | e.contextPool.Put(c) |
| 2916 | } |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | func TestDefaultRouter_Remove(t *testing.T) { |
| 2921 | var testCases = []struct { |
no test coverage detected
searching dependent graphs…