Add a new benchmark that tests the ctx acquire and release flow

this will be used later to make differences with version 3 directly visible
pull/3030/head
René 2024-04-03 22:44:56 +02:00
parent 96330a6c05
commit f098e2bd9c
1 changed files with 24 additions and 9 deletions

View File

@ -1361,15 +1361,6 @@ func Test_App_Next_Method(t *testing.T) {
utils.AssertEqual(t, 404, resp.StatusCode, "Status code")
}
// go test -v -run=^$ -bench=Benchmark_AcquireCtx -benchmem -count=4
func Benchmark_AcquireCtx(b *testing.B) {
app := New()
for n := 0; n < b.N; n++ {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
app.ReleaseCtx(c)
}
}
// go test -v -run=^$ -bench=Benchmark_App_ETag -benchmem -count=4
func Benchmark_App_ETag(b *testing.B) {
app := New()
@ -1959,3 +1950,27 @@ func Benchmark_Communication_Flow(b *testing.B) {
utils.AssertEqual(b, 200, fctx.Response.Header.StatusCode())
utils.AssertEqual(b, "Hello, World!", string(fctx.Response.Body()))
}
// go test -v -run=^$ -bench=Benchmark_Ctx_AcquireReleaseFlow -benchmem -count=4
func Benchmark_Ctx_AcquireReleaseFlow(b *testing.B) {
app := New()
fctx := &fasthttp.RequestCtx{}
b.ReportAllocs()
b.ResetTimer()
b.Run("withoutRequestCtx", func(b *testing.B) {
for n := 0; n < b.N; n++ {
c := app.AcquireCtx(fctx)
app.ReleaseCtx(c)
}
})
b.Run("withRequestCtx", func(b *testing.B) {
for n := 0; n < b.N; n++ {
c := app.AcquireCtx(&fasthttp.RequestCtx{})
app.ReleaseCtx(c)
}
})
}