From 47be68142a25475ba6ff84b270395ebd7b691cbb Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sat, 21 Dec 2024 04:51:16 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore:=20Add=20parallel=20benchm?= =?UTF-8?q?ark=20for=20Next()=20(#3259)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add parallel benchmark for Next() * Create RequestCtx outside loop --- router_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/router_test.go b/router_test.go index b47b025e..8d1e40cb 100644 --- a/router_test.go +++ b/router_test.go @@ -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) + } + }) +}