1package relay23import (4 "net/http/httptest"5 "strconv"6 "strings"7 "testing"89 "github.com/FelineStateMachine/tinyrelay/internal/event"10)1112func BenchmarkFanout(b *testing.B) {13 for _, count := range []int{10, 100, 1000} {14 b.Run("clients="+strconv.Itoa(count), func(b *testing.B) {15 r := New(testBackend{}, Config{MaxPendingBytes: 64 << 20})16 clients := make([]*client, 0, count)17 for i := 0; i < count; i++ {18 c := newClient(r, nil, httptest.NewRequest("GET", "http://relay.example/", nil))19 c.subs["all"] = subscription{filters: []event.Filter{{Kinds: []int{1}}}}20 r.clients[c] = struct{}{}21 clients = append(clients, c)22 }23 e := event.Event{ID: strings.Repeat("a", 64), Kind: 1, Content: "benchmark fanout"}24 b.ResetTimer()25 for i := 0; i < b.N; i++ {26 r.BroadcastGenerated(e)27 for _, c := range clients {28 c.mu.Lock()29 c.queue = c.queue[:0]30 c.pending = 031 c.mu.Unlock()32 }33 }34 })35 }36}