43 lines
880 B
Go
Raw Normal View History

2024-03-13 21:33:41 +00:00
package main_test
import (
"net/http"
"net/http/httptest"
"testing"
"git.akyoto.dev/go/router/testdata"
"github.com/matryer/way"
)
func BenchmarkWay(b *testing.B) {
response := &NullResponse{}
b.Run("Hello", func(b *testing.B) {
request := httptest.NewRequest("GET", helloRoute, nil)
router := way.NewRouter()
router.HandleFunc("GET", "/", func(w http.ResponseWriter, r *http.Request) {
w.Write(payload)
})
for range b.N {
router.ServeHTTP(response, request)
}
})
b.Run("GitHub", func(b *testing.B) {
request := httptest.NewRequest("GET", githubRoute, nil)
router := way.NewRouter()
for _, route := range testdata.Routes("testdata/github.txt") {
router.HandleFunc(route.Method, route.Path, func(w http.ResponseWriter, r *http.Request) {
w.Write(payload)
})
}
for range b.N {
router.ServeHTTP(response, request)
}
})
}