(b *testing.B)
| 66 | } |
| 67 | |
| 68 | func BenchmarkBuffers(b *testing.B) { |
| 69 | // Because we use the strconv.AppendFoo functions so liberally, we can't |
| 70 | // use the standard library's bytes.Buffer anyways (without incurring a |
| 71 | // bunch of extra allocations). Nevertheless, let's make sure that we're |
| 72 | // not losing any precious nanoseconds. |
| 73 | str := strings.Repeat("a", 1024) |
| 74 | slice := make([]byte, 0, 1024) |
| 75 | buf := bytes.NewBuffer(slice) |
| 76 | custom := NewPool().Get() |
| 77 | b.Run("ByteSlice", func(b *testing.B) { |
| 78 | for i := 0; i < b.N; i++ { |
| 79 | slice = append(slice, str...) |
| 80 | slice = slice[:0] |
| 81 | } |
| 82 | }) |
| 83 | b.Run("BytesBuffer", func(b *testing.B) { |
| 84 | for i := 0; i < b.N; i++ { |
| 85 | buf.WriteString(str) |
| 86 | buf.Reset() |
| 87 | } |
| 88 | }) |
| 89 | b.Run("CustomBuffer", func(b *testing.B) { |
| 90 | for i := 0; i < b.N; i++ { |
| 91 | custom.AppendString(str) |
| 92 | custom.Reset() |
| 93 | } |
| 94 | }) |
| 95 | } |
nothing calls this directly
no test coverage detected