encode_string_test.go 463 B

12345678910111213141516171819202122232425
  1. package test
  2. import (
  3. "testing"
  4. "github.com/json-iterator/go"
  5. "bytes"
  6. )
  7. func Benchmark_encode_string_with_SetEscapeHTML(b *testing.B) {
  8. type V struct {
  9. S string
  10. B bool
  11. I int
  12. }
  13. var json = jsoniter.ConfigCompatibleWithStandardLibrary
  14. b.ReportAllocs()
  15. for i := 0; i < b.N; i++ {
  16. buf := &bytes.Buffer{}
  17. enc := json.NewEncoder(buf)
  18. enc.SetEscapeHTML(true)
  19. if err := enc.Encode(V{S: "s", B: true, I: 233}); err != nil {
  20. b.Fatal(err)
  21. }
  22. }
  23. }