🧹 chore: Add parallel benchmark for Next() (#3259)

* Add parallel benchmark for Next()

* Create RequestCtx outside loop
pull/3268/head
Juan Calderon-Perez 2024-12-21 04:51:16 -05:00 committed by GitHub
parent c9ff17d796
commit 47be68142a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -889,3 +889,26 @@ func Benchmark_Router_Next_Default(b *testing.B) {
h(fctx)
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Next_Default_Parallel -benchmem -count=4
func Benchmark_Router_Next_Default_Parallel(b *testing.B) {
app := New()
app.Get("/", func(_ *Ctx) error {
return nil
})
h := app.Handler()
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
fctx := &fasthttp.RequestCtx{}
fctx.Request.Header.SetMethod(MethodGet)
fctx.Request.SetRequestURI("/")
for pb.Next() {
h(fctx)
}
})
}