MCPcopy
hub / github.com/segmentio/kafka-go / BenchmarkRequest

Function BenchmarkRequest

protocol/prototest/request.go:82–132  ·  view source on GitHub ↗
(b *testing.B, version int16, msg protocol.Message)

Source from the content-addressed store, hash-verified

80}
81
82func BenchmarkRequest(b *testing.B, version int16, msg protocol.Message) {
83 reset := load(msg)
84
85 b.Run(fmt.Sprintf("v%d", version), func(b *testing.B) {
86 buffer := &bytes.Buffer{}
87 buffer.Grow(1024)
88
89 b.Run("read", func(b *testing.B) {
90 w := io.Writer(buffer)
91
92 if err := protocol.WriteRequest(w, version, 1234, "client", msg); err != nil {
93 b.Fatal(err)
94 }
95
96 reset()
97
98 p := buffer.Bytes()
99 x := bytes.NewReader(p)
100 r := bufio.NewReader(x)
101
102 for i := 0; i < b.N; i++ {
103 _, _, _, req, err := protocol.ReadRequest(r)
104 if err != nil {
105 b.Fatal(err)
106 }
107 closeMessage(req)
108 x.Reset(p)
109 r.Reset(x)
110 }
111
112 b.SetBytes(int64(len(p)))
113 buffer.Reset()
114 })
115
116 b.Run("write", func(b *testing.B) {
117 w := io.Writer(buffer)
118 n := int64(0)
119
120 for i := 0; i < b.N; i++ {
121 if err := protocol.WriteRequest(w, version, 1234, "client", msg); err != nil {
122 b.Fatal(err)
123 }
124 reset()
125 n = int64(buffer.Len())
126 buffer.Reset()
127 }
128
129 b.SetBytes(n)
130 })
131 })
132}

Callers 3

BenchmarkProduceRequestFunction · 0.92
BenchmarkProduceRequestFunction · 0.92
BenchmarkMetadataRequestFunction · 0.92

Calls 8

WriteRequestFunction · 0.92
ReadRequestFunction · 0.92
loadFunction · 0.85
closeMessageFunction · 0.85
BytesMethod · 0.65
NewReaderMethod · 0.65
LenMethod · 0.65
ResetMethod · 0.45

Tested by 3

BenchmarkProduceRequestFunction · 0.74
BenchmarkProduceRequestFunction · 0.74
BenchmarkMetadataRequestFunction · 0.74