-
Notifications
You must be signed in to change notification settings - Fork 70
Closed
Description
Currently your benchmark code does the following:
func benchRoutes(b *testing.B, router http.Handler, routes []route) {
b.N = 10000
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, route := range routes {
router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(route.method, route.path, nil))
}
}
}The critical part is the router.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(route.method, route.path, nil)) within the loop, meaning that you allocate and initialize a new Recorder and a Request in every loop iteration.
Unfortunately that is likely much more expensive than the actual routing, meaning that both the measured memory cost and the execution time are completely meaningless, since there is a huge baseline cost.
Metadata
Metadata
Assignees
Labels
No labels