...
1 package internal
2
3 import "testing"
4
5 var byteData = []byte(`abcdef`)
6
7 const stringData = "ghijklmno"
8
9 func BenchmarkLocalBufferWithLocallyPreallocatedSliceNoAlloc(b *testing.B) {
10 b.ResetTimer()
11 for i := 0; i < b.N; i++ {
12 localBuf := LocalBuffer{Data: make([]byte, 0, 100)}
13 expectedLength := appendSomeValues(&localBuf)
14 if len(localBuf.Data) != expectedLength {
15 b.Fail()
16 }
17 }
18 }
19
20 func appendSomeValues(buf *LocalBuffer) int {
21 expectedLength := 0
22 buf.Append(byteData)
23 expectedLength += len(byteData)
24 buf.AppendString(stringData)
25 expectedLength += len(stringData)
26 buf.AppendByte('p')
27 expectedLength += 1
28 buf.AppendInt(999)
29 expectedLength += 3
30 return expectedLength
31 }
32
View as plain text