File tree 2 files changed +31
-3
lines changed
2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ func (ctx *Ctx) Format(body interface{}) {
377
377
ctx .Send (body ) // Fallback
378
378
log .Println ("Format: error serializing xml " , err )
379
379
} else {
380
- ctx .SendString ( getString ( raw ) )
380
+ ctx .Fasthttp . Response . SetBodyRaw ( raw )
381
381
}
382
382
default :
383
383
ctx .SendString (b )
@@ -515,8 +515,8 @@ func (ctx *Ctx) JSON(data interface{}) error {
515
515
}
516
516
// Set http headers
517
517
ctx .Fasthttp .Response .Header .SetContentType (MIMEApplicationJSON )
518
- ctx .SendString ( getString ( raw ) )
519
- // Success!
518
+ ctx .Fasthttp . Response . SetBodyRaw ( raw )
519
+
520
520
return nil
521
521
}
522
522
Original file line number Diff line number Diff line change @@ -1472,3 +1472,31 @@ func Benchmark_Ctx_SendBytes_With_SetBodyRaw(b *testing.B) {
1472
1472
}
1473
1473
utils .AssertEqual (b , body , c .Fasthttp .Response .Body ())
1474
1474
}
1475
+
1476
+ // go test -v -run=^$ -bench=Benchmark_Ctx_SendString_B -benchmem -count=4
1477
+ func Benchmark_Ctx_SendString_B (b * testing.B ) {
1478
+ app := New ()
1479
+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
1480
+ defer app .ReleaseCtx (c )
1481
+ body := "Hello, world!"
1482
+ b .ReportAllocs ()
1483
+ b .ResetTimer ()
1484
+ for n := 0 ; n < b .N ; n ++ {
1485
+ c .SendString (body )
1486
+ }
1487
+ utils .AssertEqual (b , []byte ("Hello, world!" ), c .Fasthttp .Response .Body ())
1488
+ }
1489
+
1490
+ // go test -v -run=^$ -bench=Benchmark_Ctx_SendBytes_B -benchmem -count=4
1491
+ func Benchmark_Ctx_SendBytes_B (b * testing.B ) {
1492
+ app := New ()
1493
+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
1494
+ defer app .ReleaseCtx (c )
1495
+ body := []byte ("Hello, world!" )
1496
+ b .ReportAllocs ()
1497
+ b .ResetTimer ()
1498
+ for n := 0 ; n < b .N ; n ++ {
1499
+ c .SendBytes (body )
1500
+ }
1501
+ utils .AssertEqual (b , []byte ("Hello, world!" ), c .Fasthttp .Response .Body ())
1502
+ }
You can’t perform that action at this time.
0 commit comments