mirror of https://github.com/gofiber/fiber.git
Add a new benchmark that tests the ctx acquire and release flow
this will be used later to make differences with version 3 directly visiblepull/3030/head
parent
96330a6c05
commit
f098e2bd9c
33
app_test.go
33
app_test.go
|
@ -1361,15 +1361,6 @@ func Test_App_Next_Method(t *testing.T) {
|
||||||
utils.AssertEqual(t, 404, resp.StatusCode, "Status code")
|
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
|
// go test -v -run=^$ -bench=Benchmark_App_ETag -benchmem -count=4
|
||||||
func Benchmark_App_ETag(b *testing.B) {
|
func Benchmark_App_ETag(b *testing.B) {
|
||||||
app := New()
|
app := New()
|
||||||
|
@ -1959,3 +1950,27 @@ func Benchmark_Communication_Flow(b *testing.B) {
|
||||||
utils.AssertEqual(b, 200, fctx.Response.Header.StatusCode())
|
utils.AssertEqual(b, 200, fctx.Response.Header.StatusCode())
|
||||||
utils.AssertEqual(b, "Hello, World!", string(fctx.Response.Body()))
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue