MCPcopy
hub / github.com/uber-go/zap / BenchmarkBuffers

Function BenchmarkBuffers

buffer/buffer_test.go:68–95  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

66}
67
68func 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}

Callers

nothing calls this directly

Calls 5

WriteStringMethod · 0.95
ResetMethod · 0.95
NewPoolFunction · 0.85
AppendStringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected