MCPcopy
hub / github.com/redis/go-redis / BenchmarkPubSubMultipleChannels

Function BenchmarkPubSubMultipleChannels

pool_pubsub_bench_test.go:274–298  ·  view source on GitHub ↗

BenchmarkPubSubMultipleChannels benchmarks subscribing to multiple channels

(b *testing.B)

Source from the content-addressed store, hash-verified

272
273// BenchmarkPubSubMultipleChannels benchmarks subscribing to multiple channels
274func BenchmarkPubSubMultipleChannels(b *testing.B) {
275 ctx := context.Background()
276 client := benchmarkClient(16)
277 defer client.Close()
278
279 channelCounts := []int{1, 5, 10, 25, 50, 100}
280
281 for _, channelCount := range channelCounts {
282 b.Run(fmt.Sprintf("Channels_%d", channelCount), func(b *testing.B) {
283 // Prepare channel names
284 channels := make([]string, channelCount)
285 for i := 0; i < channelCount; i++ {
286 channels[i] = fmt.Sprintf("channel-%d", i)
287 }
288
289 b.ResetTimer()
290 b.ReportAllocs()
291
292 for i := 0; i < b.N; i++ {
293 pubsub := client.Subscribe(ctx, channels...)
294 pubsub.Close()
295 }
296 })
297 }
298}
299
300// BenchmarkPubSubReuse benchmarks reusing PubSub connections
301func BenchmarkPubSubReuse(b *testing.B) {

Callers

nothing calls this directly

Calls 4

benchmarkClientFunction · 0.85
CloseMethod · 0.65
SubscribeMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected