Add benchmark

This commit is contained in:
Fenny 2020-06-21 11:11:45 +02:00
parent 8db7e169a3
commit 4102262dd7
2 changed files with 19 additions and 1 deletions

View File

@ -199,6 +199,24 @@ func registerDummyRoutes(app *App) {
}
}
// go test -v -run=^$ -bench=Benchmark_App_Benchmark_App_MethodNotAllowed -benchmem -count=4
func Benchmark_App_MethodNotAllowed(b *testing.B) {
app := New()
app.Get("/this/is/a/dummy/route/oke", func(c *Ctx) {
c.Send("Hello World!")
})
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/this/is/a/dummy/route/oke")
for n := 0; n < b.N; n++ {
app.handler(c)
}
utils.AssertEqual(b, 405, c.Response.StatusCode())
utils.AssertEqual(b, "GET, HEAD", string(c.Response.Header.Peek("Allow")))
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_NotFound -benchmem -count=4
func Benchmark_Router_NotFound(b *testing.B) {
app := New()

View File

@ -211,7 +211,7 @@ var methodINT = map[string]int{
MethodPatch: 8,
}
// HTTP methods and their unique INTs
// HTTP methods slice
var intMethod = []string{
MethodGet,
MethodHead,