github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/benchmarks/encode_string_test.go (about) 1 package test 2 3 import ( 4 "bytes" 5 "context" 6 "testing" 7 8 "github.com/bingoohuang/gg/pkg/jsoni" 9 ) 10 11 func Benchmark_encode_string_with_SetEscapeHTML(b *testing.B) { 12 type V struct { 13 S string 14 B bool 15 I int 16 } 17 json := jsoni.ConfigCompatibleWithStandardLibrary 18 b.ReportAllocs() 19 ctx := context.Background() 20 for i := 0; i < b.N; i++ { 21 buf := &bytes.Buffer{} 22 enc := json.NewEncoder(buf) 23 enc.SetEscapeHTML(true) 24 if err := enc.Encode(ctx, V{S: "s", B: true, I: 233}); err != nil { 25 b.Fatal(err) 26 } 27 } 28 }