(b *testing.B)
| 90 | } |
| 91 | |
| 92 | func BenchmarkJsonMarshal(b *testing.B) { |
| 93 | inputStrings := [][]string{ |
| 94 | {"largestring", strings.Repeat("a", 1024)}, |
| 95 | {"smallstring", "abcdef"}, |
| 96 | {"specialchars", "<><>^)(*&(%*&%&^$*&%)(*&)^)"}, |
| 97 | } |
| 98 | |
| 99 | var result []byte |
| 100 | |
| 101 | for _, input := range inputStrings { |
| 102 | b.Run(fmt.Sprintf("STDJsonMarshal-%s", input[0]), func(b *testing.B) { |
| 103 | for i := 0; i < b.N; i++ { |
| 104 | result, _ = json.Marshal(input[1]) |
| 105 | } |
| 106 | }) |
| 107 | |
| 108 | b.Run(fmt.Sprintf("stringJsonMarshal-%s", input[0]), func(b *testing.B) { |
| 109 | for i := 0; i < b.N; i++ { |
| 110 | result = stringJsonMarshal(input[1]) |
| 111 | } |
| 112 | }) |
| 113 | } |
| 114 | |
| 115 | _ = result |
| 116 | } |
| 117 | |
| 118 | func TestStringJsonMarshal(t *testing.T) { |
| 119 | inputs := []string{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…