MCPcopy
hub / github.com/gorilla/websocket / BenchmarkBroadcast

Function BenchmarkBroadcast

conn_broadcast_test.go:101–131  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

99}
100
101func BenchmarkBroadcast(b *testing.B) {
102 benchmarks := []struct {
103 name string
104 usePrepared bool
105 compression bool
106 }{
107 {"NoCompression", false, false},
108 {"Compression", false, true},
109 {"NoCompressionPrepared", true, false},
110 {"CompressionPrepared", true, true},
111 }
112 payload := textMessages(1)[0]
113 for _, bm := range benchmarks {
114 b.Run(bm.name, func(b *testing.B) {
115 bench := newBroadcastBench(bm.usePrepared, bm.compression)
116 defer bench.close()
117 b.ResetTimer()
118 for i := 0; i < b.N; i++ {
119 message := &broadcastMessage{
120 payload: payload,
121 }
122 if bench.usePrepared {
123 pm, _ := NewPreparedMessage(TextMessage, message.payload)
124 message.prepared = pm
125 }
126 bench.broadcastOnce(message)
127 }
128 b.ReportAllocs()
129 })
130 }
131}

Callers

nothing calls this directly

Calls 5

textMessagesFunction · 0.85
newBroadcastBenchFunction · 0.85
NewPreparedMessageFunction · 0.85
closeMethod · 0.80
broadcastOnceMethod · 0.80

Tested by

no test coverage detected