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

Function BenchmarkConn

conn_test.go:1175–1230  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1173const benchmarkMessageCount = 100
1174
1175func BenchmarkConn(b *testing.B) {
1176 benchmarks := []struct {
1177 scenario string
1178 function func(*testing.B, *Conn, []byte)
1179 }{
1180 {
1181 scenario: "Seek",
1182 function: benchmarkConnSeek,
1183 },
1184
1185 {
1186 scenario: "Read",
1187 function: benchmarkConnRead,
1188 },
1189
1190 {
1191 scenario: "ReadBatch",
1192 function: benchmarkConnReadBatch,
1193 },
1194
1195 {
1196 scenario: "ReadOffsets",
1197 function: benchmarkConnReadOffsets,
1198 },
1199
1200 {
1201 scenario: "Write",
1202 function: benchmarkConnWrite,
1203 },
1204 }
1205
1206 topic := makeTopic()
1207 value := make([]byte, 10e3) // 10 KB
1208 msgs := make([]Message, benchmarkMessageCount)
1209
1210 for i := range msgs {
1211 msgs[i].Value = value
1212 }
1213
1214 conn, _ := DialLeader(context.Background(), "tcp", "localhost:9092", topic, 0)
1215 defer conn.Close()
1216
1217 if _, err := conn.WriteMessages(msgs...); err != nil {
1218 b.Fatal(err)
1219 }
1220
1221 for _, benchmark := range benchmarks {
1222 b.Run(benchmark.scenario, func(b *testing.B) {
1223 if _, err := conn.Seek(0, SeekStart); err != nil {
1224 b.Error(err)
1225 return
1226 }
1227 benchmark.function(b, conn, value)
1228 })
1229 }
1230}
1231
1232func benchmarkConnSeek(b *testing.B, conn *Conn, _ []byte) {

Callers

nothing calls this directly

Calls 6

DialLeaderFunction · 0.85
makeTopicFunction · 0.70
CloseMethod · 0.45
WriteMessagesMethod · 0.45
SeekMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected