package web_test import ( "net/http/httptest" "strings" "testing" "git.akyoto.dev/go/router/testdata" "git.akyoto.dev/go/web" ) func BenchmarkStatic(b *testing.B) { paths := []string{ "/", "/hello", "/hello/world", } s := web.NewServer() for _, path := range paths { s.Get(path, func(ctx web.Context) error { return ctx.String("Hello") }) } for _, path := range paths { b.Run(strings.TrimPrefix(path, "/"), func(b *testing.B) { request := httptest.NewRequest("GET", path, nil) response := &NullResponse{} for range b.N { s.ServeHTTP(response, request) } }) } } func BenchmarkGitHub(b *testing.B) { paths := []string{ "/gists/:id", "/repos/:a/:b", } s := web.NewServer() for _, route := range testdata.Routes("testdata/github.txt") { s.Router().Add(route.Method, route.Path, func(ctx web.Context) error { return ctx.String("Hello") }) } for _, path := range paths { b.Run(strings.TrimPrefix(path, "/"), func(b *testing.B) { request := httptest.NewRequest("GET", path, nil) response := &NullResponse{} for range b.N { s.ServeHTTP(response, request) } }) } }