2024-03-12 19:35:19 +00:00
|
|
|
package server_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2024-03-13 19:18:01 +00:00
|
|
|
"git.akyoto.dev/go/router/testdata"
|
2024-03-12 19:35:19 +00:00
|
|
|
"git.akyoto.dev/go/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkHello(b *testing.B) {
|
|
|
|
request := httptest.NewRequest("GET", "/", nil)
|
|
|
|
response := &NullResponse{}
|
|
|
|
s := server.New()
|
|
|
|
|
|
|
|
s.Get("/", func(ctx server.Context) error {
|
|
|
|
return ctx.String("Hello")
|
|
|
|
})
|
|
|
|
|
|
|
|
for range b.N {
|
|
|
|
s.ServeHTTP(response, request)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkGitHub(b *testing.B) {
|
|
|
|
request := httptest.NewRequest("GET", "/repos/:owner/:repo", nil)
|
|
|
|
response := &NullResponse{}
|
|
|
|
s := server.New()
|
|
|
|
|
2024-03-13 19:18:01 +00:00
|
|
|
for _, route := range testdata.Routes("testdata/github.txt") {
|
2024-03-12 21:31:45 +00:00
|
|
|
s.Router.Add(route.Method, route.Path, func(server.Context) error {
|
2024-03-12 19:35:19 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for range b.N {
|
|
|
|
s.ServeHTTP(response, request)
|
|
|
|
}
|
|
|
|
}
|