Skip to content

Commit

Permalink
Add a new benchmark that tests the ctx acquire and release flow
Browse files Browse the repository at this point in the history
this will be used later to make differences with version 3 directly visible
  • Loading branch information
ReneWerner87 committed Apr 3, 2024
1 parent 96330a6 commit f098e2b
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions app_test.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
})
}

0 comments on commit f098e2b

Please sign in to comment.