64 lines
1.1 KiB
Go

package server_test
import (
"net/http/httptest"
"strings"
"testing"
"git.akyoto.dev/go/router/testdata"
"git.akyoto.dev/go/server"
)
func BenchmarkStatic(b *testing.B) {
paths := []string{
"/",
"/hello",
"/hello/world",
}
s := server.New()
for _, path := range paths {
s.Get(path, func(ctx server.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 := server.New()
for _, route := range testdata.Routes("testdata/github.txt") {
s.Router().Add(route.Method, route.Path, func(ctx server.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)
}
})
}
}