Skip to content

Commit

Permalink
🧹 chore: Add parallel benchmark for Next() (#3259)
Browse files Browse the repository at this point in the history
* Add parallel benchmark for Next()

* Create RequestCtx outside loop
  • Loading branch information
gaby authored Dec 21, 2024
1 parent c9ff17d commit 47be681
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

0 comments on commit 47be681

Please sign in to comment.