@@ -1881,6 +1881,14 @@ func Benchmark_NewError(b *testing.B) {
18811881 }
18821882}
18831883
1884+ func Benchmark_NewError_Parallel (b * testing.B ) {
1885+ b .RunParallel (func (pb * testing.PB ) {
1886+ for pb .Next () {
1887+ NewError (200 , "test" ) //nolint:errcheck // not needed
1888+ }
1889+ })
1890+ }
1891+
18841892// go test -run Test_NewError
18851893func Test_NewError (t * testing.T ) {
18861894 t .Parallel ()
@@ -2835,6 +2843,34 @@ func Benchmark_Communication_Flow(b *testing.B) {
28352843 require .Equal (b , "Hello, World!" , string (fctx .Response .Body ()))
28362844}
28372845
2846+ func Benchmark_Communication_Flow_Parallel (b * testing.B ) {
2847+ app := New ()
2848+
2849+ app .Get ("/" , func (c Ctx ) error {
2850+ return c .SendString ("Hello, World!" )
2851+ })
2852+
2853+ h := app .Handler ()
2854+
2855+ b .ReportAllocs ()
2856+ b .RunParallel (func (pb * testing.PB ) {
2857+ fctx := & fasthttp.RequestCtx {}
2858+ fctx .Request .Header .SetMethod (MethodGet )
2859+ fctx .Request .SetRequestURI ("/" )
2860+ for pb .Next () {
2861+ h (fctx )
2862+ }
2863+ })
2864+
2865+ verifyCtx := & fasthttp.RequestCtx {}
2866+ verifyCtx .Request .Header .SetMethod (MethodGet )
2867+ verifyCtx .Request .SetRequestURI ("/" )
2868+ h (verifyCtx )
2869+
2870+ require .Equal (b , 200 , verifyCtx .Response .Header .StatusCode ())
2871+ require .Equal (b , "Hello, World!" , string (verifyCtx .Response .Body ()))
2872+ }
2873+
28382874// go test -v -run=^$ -bench=Benchmark_Ctx_AcquireReleaseFlow -benchmem -count=4
28392875func Benchmark_Ctx_AcquireReleaseFlow (b * testing.B ) {
28402876 app := New ()
@@ -2860,6 +2896,44 @@ func Benchmark_Ctx_AcquireReleaseFlow(b *testing.B) {
28602896 })
28612897}
28622898
2899+ func acquireDefaultCtxForAppBenchmark (b * testing.B , app * App , fctx * fasthttp.RequestCtx ) * DefaultCtx {
2900+ b .Helper ()
2901+
2902+ ctx := app .AcquireCtx (fctx )
2903+ defaultCtx , ok := ctx .(* DefaultCtx )
2904+ if ! ok {
2905+ b .Fatal ("AcquireCtx did not return *DefaultCtx" )
2906+ }
2907+ return defaultCtx
2908+ }
2909+
2910+ func Benchmark_Ctx_AcquireReleaseFlow_Parallel (b * testing.B ) {
2911+ app := New ()
2912+
2913+ b .Run ("withoutRequestCtx" , func (b * testing.B ) {
2914+ b .ReportAllocs ()
2915+
2916+ b .RunParallel (func (pb * testing.PB ) {
2917+ fctx := & fasthttp.RequestCtx {}
2918+ for pb .Next () {
2919+ c := acquireDefaultCtxForAppBenchmark (b , app , fctx )
2920+ app .ReleaseCtx (c )
2921+ }
2922+ })
2923+ })
2924+
2925+ b .Run ("withRequestCtx" , func (b * testing.B ) {
2926+ b .ReportAllocs ()
2927+
2928+ b .RunParallel (func (pb * testing.PB ) {
2929+ for pb .Next () {
2930+ c := acquireDefaultCtxForAppBenchmark (b , app , & fasthttp.RequestCtx {})
2931+ app .ReleaseCtx (c )
2932+ }
2933+ })
2934+ })
2935+ }
2936+
28632937func TestErrorHandler_PicksRightOne (t * testing.T ) {
28642938 t .Parallel ()
28652939 // common handler to be used by all routes,
0 commit comments